cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## Running total with Fact, Date and Dim table

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.

Could you please provide any support?

1 ACCEPTED SOLUTION
Community Support

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
6 REPLIES 6
Super User

Hi,

Regards,
Ashish Mathur
http://www.ashishmathur.com
Frequent Visitor
Super User

I just cannot relate the table you posted in the first message with the table in the PBI file.  Just completely confused.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Frequent Visitor

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!

Community Support

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Frequent Visitor

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``````

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

#### Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

#### Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors