Forum Discussion
Running total with Fact, Date and Dim table
- Anonymous2 years ago
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 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