我有一段时间没有写过DAX,我有点困难,我希望有人可以提出建议。
我有什么:
数量表(比1月多很多个月):
+----------+-----------+------------+-----------+---------+-----------+--------+
| Location | DateFrom | DateTo | MonthFrom | MonthTo | RateType | Amount |
+----------+-----------+------------+-----------+---------+-----------+--------+
| NY | 1/1/2017 | 6/30/2017 | 1 | 6 | LaborRate | 129.7 |
| NY | 7/1/2017 | 9/30/2017 | 7 | 9 | LaborRate | 129.8 |
| NY | 10/1/2017 | 12/31/2017 | 10 | 12 | LaborRate | 129.9 |
| DC | 1/1/2017 | 6/30/2017 | 1 | 6 | LaborRate | 130.1 |
| DC | 7/1/2017 | 9/30/2017 | 7 | 9 | LaborRate | 130.5 |
| DC | 10/1/2017 | 12/31/2017 | 10 | 12 | LaborRate | 130.7 |
+----------+-----------+------------+-----------+---------+-----------+--------+
费率表:
+-------+----------+-----------+------------+
| Month | LaborQty | LaborRate | Result |
+-------+----------+-----------+------------+
| 1 | 674.22 | 129.74 | 87473.3 |
| 2 | 350 | 129.74 | 45409 |
| 3 | 375 | 129.74 | 48652.5 |
| 4 | 400 | 129.74 | 51896 |
| 5 | 380 | 129.74 | 49301.2 |
| 6 | 500 | 129.74 | 64870 |
| 7 | 550 | 129.76 | 71368 |
| 8 | 600 | 129.76 | 77856 |
| 9 | 675 | 129.76 | 87588 |
| 10 | 700 | 129.98 | 90986 |
| 11 | 780 | 129.98 | 101384.4 |
+-------+----------+-----------+------------+
本月所需的输出类型(例如,LaborQty x LaborRate):
LaborRate = db.Rates
.Where(a => a.DateFrom <= SelectedDate & a.DateTo >= SelectedDate & a.RateType == "LaborRate")
.Select(a => a.Amount).Sum();
我想写的是什么:
DAX度量将输出与结果列中显示的量相同的量。如果我在哪里写一个linq查询来选择正确的速率,它将看起来像这样:
New-ModuleManifest
我尝试了CALCULATE,SUM,SUMX,FILTER,RELATED的组合,但我无法让它工作。任何建议将不胜感激。什么是最简单的方法?
答案 0 :(得分:1)
我能够通过以下方式实现这一目标。
Month = MONTH(Qty[Date])
作为计算列添加到Qty
表格。TotalLaborQty
表格中Qty
创建一个SUM(Qty[LaborQty])
指标。LaborRate
表格中定义Rates
度量,详情如下。Result
度量定义为[TotalLaborQty] * [LaborRate]
。Qty[Location]
和Qty[Month]
,值为三个度量。LaborRate =
VAR SelectedMonth = SELECTEDVALUE(Qty[Month])
VAR SelectedLocation = SELECTEDVALUE(Qty[Location])
RETURN CALCULATE(SUM(Rates[Amount]),
FILTER(ALL(Rates),
Rates[MonthFrom] <= SelectedMonth &&
Rates[MonthTo] >= SelectedMonth &&
Rates[Location] = SelectedLocation))