March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I'm trying to calculate a running total, I've tried window function and the standard way of calculating using dax, but it is not working.
Let me explain my scenario:
I have a Calendar table, a dim table and three facts table. Each fact is connected to the Calendar table and the dim table, that I use as filters and as rows in my table.
Date is the key from Facts and Calendar Table.
Material&Plant is the key from the Facts and the Dim Table.
Finally, from the fact, I have a measure called "ProjectedInventory" that is a calculation three measures in each of the fact tables.
That gives me this kind of table:
The goal is to calculate the running total of the Projected Inventory (last column in table) reseting in every MatPlant combination.
Here is the link to a sample file: https://drive.google.com/file/d/15574W_Mrw3FNgB9sUIn0hEH-TrJvudZd/view?usp=drive_link
Could you please provide any support?
Thanks in advance
Solved! Go to Solution.
Hi @fonsogijon ,
You can create a measure as below to get it:
Measure =
VAR _dim1 =
SELECTEDVALUE ( 'Dim'[Dim1] )
VAR _dim2 =
SELECTEDVALUE ( 'Dim'[Dim2] )
VAR _date =
SELECTEDVALUE ( 'Calendar'[Date] )
RETURN
SUMX (
FILTER (
ALLSELECTED ( 'Facttable' ),
'Facttable'[Dim1] = _dim1
&& 'Facttable'[Dim2] = _dim2
&& 'Facttable'[Date] <= _date
),
[Projected]
)
If the above one can't help you figure out, please provide some raw data in your dimension table and fact table (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:
How to provide sample data in the Power BI Forum
And it is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Hi,
Share the download link of the PBI file.
I just cannot relate the table you posted in the first message with the table in the PBI file. Just completely confused.
The mapping would be the following:
TABLE | PBI |
Year | Year |
Month | Month |
Dim1 | Plant_cd |
Dim2 | Material_cd |
Didn't include because did not consider relevant | Inv On hand |
Measure_Fact1 | OpenProdOrder |
Measure_Fact2 | Forecast CM |
Projected | ProjectedInventory |
Goal Acc Sum | No column, running total of the Projected Inventory (last column in table) by every dim |
PBI file I have, more dim columns, because they can be selected in the parameter.
The goal is to calculate the running total of the Projected Inventory (last column in table) by every dim. If it is confusing I can remove table from example and just add the link to the file.
Thanks!
Hi @fonsogijon ,
You can create a measure as below to get it:
Measure =
VAR _dim1 =
SELECTEDVALUE ( 'Dim'[Dim1] )
VAR _dim2 =
SELECTEDVALUE ( 'Dim'[Dim2] )
VAR _date =
SELECTEDVALUE ( 'Calendar'[Date] )
RETURN
SUMX (
FILTER (
ALLSELECTED ( 'Facttable' ),
'Facttable'[Dim1] = _dim1
&& 'Facttable'[Dim2] = _dim2
&& 'Facttable'[Date] <= _date
),
[Projected]
)
If the above one can't help you figure out, please provide some raw data in your dimension table and fact table (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:
How to provide sample data in the Power BI Forum
And it is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
I managed to get the soution base on your reply! So thanks for that.
Maybe I complicated things, but on the sample file, this measure is working in my case 🙂
ProjectedInventory =
VAR _dim1 =
SELECTEDVALUE ( 'Dimensions'[Material_cd] )
VAR _dim2 =
SELECTEDVALUE ( 'Dimensions'[Plant_cd] )
VAR _dateyear =
SELECTEDVALUE ( 'CalendarTable'[Date].[Year] )
VAR _datemonth =
SELECTEDVALUE ( 'CalendarTable'[Date].[Month] )
var _monthvalue =
SWITCH(TRUE(),
_datemonth = "January", 1,
_datemonth = "February", 2,
_datemonth = "March", 3,
_datemonth = "April", 4,
_datemonth = "May", 5,
_datemonth = "June", 6,
_datemonth = "July", 7,
_datemonth = "August", 8,
_datemonth = "September", 9,
_datemonth = "October", 10,
_datemonth = "November", 11,
_datemonth = "December", 12,
BLANK())
var _current =
CALCULATE(
SUMX (
FILTER (
ALLSELECTED ( Inventory ),
Inventory [Material_cd] = _dim1
&& Inventory[Plant_cd] = _dim2
&& YEAR(Inventory[CalendarDay]) <= _dateyear
&& MONTH(Inventory[CalendarDay]) <= _monthvalue
),
[Last Day Qty On Hand]
)
+
SUMX (
FILTER (
ALLSELECTED ( 'Open ProdOrder' ),
'Open ProdOrder' [Material_cd] = _dim1
&& 'Open ProdOrder'[Plant_cd] = _dim2
&& YEAR('Open ProdOrder'[FinishDate_MfgOrder]) <= _dateyear
&& MONTH('Open ProdOrder'[FinishDate_MfgOrder]) <= _monthvalue
),
[OpenProdOrder]
)
-
SUMX (
FILTER (
ALLSELECTED ( 'Forecast CM' ),
'Forecast CM' [Material_cd] = _dim1
&& 'Forecast CM'[Plant_cd] = _dim2
&& YEAR('Forecast CM'[CalMonth]) <= _dateyear
&& MONTH('Forecast CM'[CalMonth]) <= _monthvalue
),
[Forecast CM]
),
CalendarTable[Current]="Y")
var _future =
CALCULATE(
SUMX (
FILTER (
ALLSELECTED ( 'Open ProdOrder' ),
'Open ProdOrder' [Material_cd] = _dim1
&& 'Open ProdOrder'[Plant_cd] = _dim2
&& YEAR('Open ProdOrder'[FinishDate_MfgOrder]) <= _dateyear
&& MONTH('Open ProdOrder'[FinishDate_MfgOrder]) <= _monthvalue
),
[OpenProdOrder]
)
-
SUMX (
FILTER (
ALLSELECTED ( 'Forecast CM' ),
'Forecast CM' [Material_cd] = _dim1
&& 'Forecast CM'[Plant_cd] = _dim2
&& YEAR('Forecast CM'[CalMonth]) <= _dateyear
&& MONTH('Forecast CM'[CalMonth]) <= _monthvalue
),
[Forecast CM]
),
CalendarTable[CurrentFuture]="Y" && CalendarTable[Current]<>"Y")
RETURN _current+_future
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
108 | |
73 | |
53 | |
52 | |
44 |
User | Count |
---|---|
161 | |
110 | |
69 | |
58 | |
50 |