Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
fuulhouse
Frequent Visitor

Help with Cumulative DAX Measure with Filter

Hello community,

I am new to DAX and need help with what I am working on in PBI. I am sorry my writeup is a bit wordy.

 

The cumulative cash flow for each project start from the beginning of the project till the end. For projects still ongoing, it cumulates till the current date. I applied period slicer for Year and Month. What I am trying to achieve is that for any particular period, only the projects active during that period should be returned on the table i.e for 2017, I want to see data for only Jobs 1707, 1702, 1703, while others are filtered out. Also if I chose 2021 on my slicer, I would like to see data for Jobs 2001, 2003, 2004, 2101, 2102, 2103, 2105 because they are the only jobs active during the period. I am able to achieve this on the table only when the cumulative measure is not added. Once it is added and a period in the slicer is selected, the table returns all the Job number. The cumulative measure is needed because the net Cash and cumulative net Cash for ongoing projects are not the same in the same period.

 

The DaX in cumulative net Cash Flow measure is as follows:

 

Cumulative Net Cash Flow = CALCULATE(
    [Net Cash Flow],
    FILTER(
        ALLSELECTED('DimDate'[Date]),
        ISONORAFTER('DimDate'[Date], MAX('DimDate'[Date]), DESC)
    )
)

 

**DimDate is my Dimension Date Table.

 

Because the Cash, Cashout and Project Numbers are all in different tables, I used a dimension Date table in my model. Any help with on how to filter out Jobs that are not active during a period will be appreciated.

 

**A sample table is attached. Data are representative only.

 

Job NumberStart YearStart MonthLast Transaction YearLast Transaction MonthTotal Cash inTotal Cash outNet CashCum Net Cash Flow

1701201702201905 $        10,000.00 $             4,500.00 $            5,500.00 $                        5,500.00
1702201704201908 $        12,000.00 $             9,000.00 $            3,000.00 $                        3,000.00
1703201706202002 $        23,000.00 $           19,874.00 $            3,126.00 $                        3,126.00
1802201807202008 $          1,800.00 $           12,785.00 $       (10,985.00) $                   (10,985.00)
1803201807202107 $          2,300.00 $           20,132.00 $       (17,832.00) $                   (17,832.00)
1805201804201908 $        35,000.00 $           22,983.00 $          12,017.00 $                      12,017.00
1903201909202010 $        12,000.00 $           20,964.00 $          (8,964.00) $                      (8,964.00)
1905201907202103 $        25,000.00 $           18,765.00 $            6,235.00 $                        6,235.00
1906201908202009 $        33,000.00 $           21,098.00 $          11,902.00 $                      11,902.00
2001202003202111 $        45,000.00 $           65,324.00 $       (20,324.00) $                   (32,980.00)
2002202004202012 $        60,888.00 $           23,782.00 $          37,106.00 $                      37,106.00
2003202002202107 $        39,766.00 $           11,896.00 $          27,870.00 $                      27,870.00
2004202005202109 $        22,545.00 $           27,476.00 $          (4,931.00) $                      (3,338.00)
2101202106202111 $        23,454.00 $           35,447.00 $       (11,993.00) $                      (5,467.00)
2102202106202110 $        12,678.00 $           15,365.00 $          (2,687.00) $                        4,056.00
2103202109202111 $        44,754.00 $           63,785.00 $       (19,031.00) $                   (24,656.00)
2105202103202111 $        33,907.00 $           32,765.00 $            1,142.00 $                      (2,000.00)
1 ACCEPTED SOLUTION

Thank you @v-yanjiang-msft . I looked at the sample you created and it did the magic.

The Date table is connected to the fact table by a Datekey. Also, the 1803 and 1905 thing were typos.  

View solution in original post

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @fuulhouse ,

According to your description, if you want to calculate the accumulated value of net cash flow, you can write it like this:

Cumulative Net Cash Flow =
SUMX (
    FILTER (
        ALLSELECTED( 'Table' ),
        'Table'[Job Number] <= MAX ( 'Table'[Job Number] )
            && 'Table'[Start Year] = MAX ( 'Table'[Start Year] )
    ),
    [Net cash flow]
)

Is the value of Cumulative Net Cash Flow your expected outcome?

vkalyjmsft_0-1638526953446.png

 

I have some unclear points about your sample:

1.Is Date column in DimDate table a date type? How does it make relationship with the table of Start Year, as they are not the same data type.

2.The Last Transaction Year of 1803 and 1905 is 2021, why didn’t them return when you choose 2021 on slicer?

 

I cannot reproduce your problem in my sample, I attach my sample below, would you modify it and post again? It’s best to reflect your problem in the sample, so that I know where the problem is.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @v-yanjiang-msft . I looked at the sample you created and it did the magic.

The Date table is connected to the fact table by a Datekey. Also, the 1803 and 1905 thing were typos.  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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