Skip to main content
cancel
Showing results for 
Search instead 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

Reply
fonsogijon
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:

 

DSI.jpg

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

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
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.

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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
https://www.linkedin.com/in/excelenthusiasts/

The mapping would be the following:

 

TABLEPBI
YearYear
MonthMonth
 Dim1 Plant_cd
 Dim2 Material_cd
Didn't include because did not consider relevantInv On hand
 Measure_Fact1 OpenProdOrder
 Measure_Fact2 Forecast CM
 Projected ProjectedInventory
 Goal Acc SumNo 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!

 



v-yiruan-msft
Community Support
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.

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

Helpful resources

Announcements
Europe Fabric Conference

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.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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