我有"销售"具有团队ID,付款类型和日期的表格(请参阅下面的示例):
我想写一个DAX公式,它将"查找"上个月"每月"的销售额;团队和"季度"的前3个月销售额球队。查询还需要按团队ID进行过滤,因此先前的销售属于同一团队。
以下是所需输出(销售变化)的示例:
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.JFrame;
public class Grid {
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame("Grid Layout");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
frame.setResizable(false);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(9, 9, 5, 5));
int i, j;
for (i = 1; i <= 9; i++) {
for (j = 1; j <= 9; j++) {
FactButton button = new FactButton(i + " x " + j);
panel.add(button);
}
}
frame.add(panel);
frame.setVisible(true);
}
});
}
}
class FactButton extends JToggleButton {
private static final long serialVersionUID = 1L;
String orgText;
public FactButton(String orgText) {
this.orgText = orgText;
setText(orgText);
addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent evt) {
if (evt.getStateChange() == ItemEvent.SELECTED) {
String prob = getText();
String left = prob.substring(0, prob.indexOf(" "));
String right = prob.substring(prob.indexOf(" ") + 3, prob.length());
int i = Integer.parseInt(left);
int j = Integer.parseInt(right);
setText(i * j + "");
} else if (evt.getStateChange() == ItemEvent.DESELECTED) {
setText(orgText);
}
}
});
}
}
这些公式显然不能产生预期的结果,但我在这里分享它们以显示我解决这个问题的方法。也许,这里知识渊博的人可以帮助正确的语法和逻辑。
谢谢!
答案 0 :(得分:0)
要计算上个月/季度的总和,您可以添加计算列。但是,您需要将月份列更改为日期。 jan 16 =&gt; 2016年1月1日
式:
=
IF (
myTable[paymenttype] = "monthly",
CALCULATE (
SUM ( myTable[sales] ),
FILTER (
myTable,
myTable[TeamID] = EARLIER ( myTable[TeamID] )
&& DATEADD ( myTable[date], 1, MONTH ) = EARLIER ( myTable[date] )
&& myTable[paymenttype] = EARLIER ( myTable[paymenttype] )
)
),
CALCULATE (
SUM ( myTable[sales] ),
FILTER (
myTable,
myTable[TeamID] = EARLIER ( myTable[TeamID] )
&& DATEADD ( myTable[date], 3, MONTH ) = EARLIER ( myTable[date] )
&& myTable[paymenttype] = EARLIER ( myTable[paymenttype] )
)
)
)