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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
AKath_12
Frequent Visitor

How to carry forward the data to next month until new data is available?

Hi, 

 

I have struggled with the DAX formula and hope an expert here could help. 

 

I have a data set that inputs on an approximately yearly basis. However, in my display result, I would like the latest data to be carried forward to the next month until a new data value is available. 

 

For example, the data input from November 2021 and onwards should display 2.38, and the next data available is September 2022 and onwards should display 2.54. 

 

Note: I have a date table which actively linked to one of my data sets. However, the average result is pulled from another dataset, which has an inactive relationship with the date table. Not sure if this is relevant, hope this provides more information about the solution. Many thanks!

 

AKath_12_0-1727420284681.png

 

2 ACCEPTED SOLUTIONS
dharmendars007
Super User
Super User

Hello @AKath_12 , 

 

Since you mentioned that the "average result" is pulled from a dataset with an inactive relationship to the date table, make sure that you activate this relationship within your DAX query when needed. You can use USERRELATIONSHOT() to activate the inactive relationship.

 

Carry Forward Result =
VAR LastValue =
CALCULATE(
MAX('YourDataTable'[Result]),USERELATIONSHIP('YourDateTable'[Date], 'YourDataTable'[Date]),
FILTER(ALL('YourDataTable'),'YourDataTable'[Date] <= MAX('YourDateTable'[Date])))
RETURN
LastValue

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

 

 

View solution in original post

SachinNandanwar
Super User
Super User

I have used a sample data that has Date in the same table as the values.

Sample Data >>

SachinNandanwar_0-1727452627525.png


and used the following measure to get the expected output.

MEASURE =
VAR _Curr_Date =
    MAX ( '1'[Date] )
VAR _SummarizeVar =
    CALCULATE (
        MAX ( '1'[Date].[Date] ),
        FILTER ( ALL ( '1' ), [Date] < _Curr_Date && [Value] > 0 )
    )
VAR _LatestValue =
    LOOKUPVALUE ( '1'[Value], '1'[Date], _SummarizeVar )
RETURN
    IF (
        SELECTEDVALUE ( '1'[Value], 0.00 ) = 0,
        _LatestValue,
        SELECTEDVALUE ( '1'[Value] )
    )


You can adjust the above measure to include the relationship across the Date table.

Output >>

SachinNandanwar_1-1727452660466.png

 






Regards,
Sachin
Check out my Blog

View solution in original post

7 REPLIES 7
AKath_12
Frequent Visitor

Hi, 

 

I just realized the solution given is not quite right. The data shows the Max result value instead of providing the latest result value. I have generated a file as below:-

 

@dharmendars007 @SachinNandanwar, could you please help and relook into the solution? Thank you very much!

 

https://drive.google.com/file/d/1fR9R1Yl2Zs1NaE5zeBWEt5Hn8X08MZy-/view?usp=drive_link

 

 

AKath_12
Frequent Visitor

Thank you both @SachinNandanwar , @dharmendars007  for resolving the issue. the script provided earlier is very helpful. I didn't get it earlier due to the relationship between my calendar and the dataset. I have finally got the correct value after fixing it.=)

 

 

SachinNandanwar
Super User
Super User

I have used a sample data that has Date in the same table as the values.

Sample Data >>

SachinNandanwar_0-1727452627525.png


and used the following measure to get the expected output.

MEASURE =
VAR _Curr_Date =
    MAX ( '1'[Date] )
VAR _SummarizeVar =
    CALCULATE (
        MAX ( '1'[Date].[Date] ),
        FILTER ( ALL ( '1' ), [Date] < _Curr_Date && [Value] > 0 )
    )
VAR _LatestValue =
    LOOKUPVALUE ( '1'[Value], '1'[Date], _SummarizeVar )
RETURN
    IF (
        SELECTEDVALUE ( '1'[Value], 0.00 ) = 0,
        _LatestValue,
        SELECTEDVALUE ( '1'[Value] )
    )


You can adjust the above measure to include the relationship across the Date table.

Output >>

SachinNandanwar_1-1727452660466.png

 






Regards,
Sachin
Check out my Blog

Thank you very much @SachinNandanwar and @dharmendars007 

 

I tried to combine both DAX formulas, however, the result was not as expected. So I changed it to the formula below instead, it turns out gave me consecutive results for each month, however, it auto-average the result and the month displayed did not seem quite right.

 

CALCULATE('Scores by Questions'[Average Score this year],
    USERELATIONSHIP('Date'[Date],'All'[Start Date]),
    FILTER(ALL('Date'),'Date'[Date]<= MAX('Date'[Date])))
AKath_12_1-1727755599411.png

2.54 should have been displayed from November onwards, however, the result showed 2.46, and displayed wrongly from Sept onwards instead.

 

The same goes for result 3.44 should be displayed from Dec 2023 onwards, however, 2.71 displayed in June 2023 instead.


 

The indirect relationship that I have used is Many to one and single cross-filter direction. 
 
Looking forward to more of your advice! Thank you!
 
 

Please share the data.



Regards,
Sachin
Check out my Blog

Hi Sachin, sorry for my late reply. I'm not sure how to attach the file here. Do you have an email so I can send it to you? 

 

AKath_12_0-1729135053348.png

 

The raw data is as below:-

NumberQuestionScoresMax ScoresStart TimeEnd TimeAverage Scores
1M269/30/2018 20:3211/13/2018 20:332
1S269/30/2018 20:3211/13/2018 20:332
1C369/30/2018 20:3211/13/2018 20:333
1P469/30/2018 20:3211/13/2018 20:334
1T469/30/2018 20:3211/13/2018 20:334
1P469/30/2018 20:3211/13/2018 20:334
1C269/30/2018 20:3211/13/2018 20:332
1E469/30/2018 20:3211/13/2018 20:334
1S369/30/2018 20:3211/13/2018 20:333
1B269/30/2018 20:3211/13/2018 20:332
1G269/30/2018 20:3211/13/2018 20:332
2M266/10/2019 1:006/12/2019 9:002
2S266/10/2019 1:006/12/2019 9:002
2C266/10/2019 1:006/12/2019 9:002
2C266/10/2019 1:006/12/2019 9:002
2P266/10/2019 1:006/12/2019 9:002
2T266/10/2019 1:006/12/2019 9:002
2S266/10/2019 1:006/12/2019 9:002
2P266/10/2019 1:006/12/2019 9:002
2C466/10/2019 1:006/12/2019 9:004
2D266/10/2019 1:006/12/2019 9:002
2E366/10/2019 1:006/12/2019 9:003
2S266/10/2019 1:006/12/2019 9:002
2P366/10/2019 1:006/12/2019 9:003
3M2611/25/2020 0:0011/27/2020 10:002
3S2611/25/2020 0:0011/27/2020 10:002
3C3611/25/2020 0:0011/27/2020 10:003
3C2611/25/2020 0:0011/27/2020 10:002
3P4611/25/2020 0:0011/27/2020 10:004
3S2611/25/2020 0:0011/27/2020 10:002
3C2611/25/2020 0:0011/27/2020 10:002
3C2611/25/2020 0:0011/27/2020 10:002
310 : /4611/25/2020 0:0011/27/2020 10:004
3E2611/25/2020 0:0011/27/2020 10:002
3S2611/25/2020 0:0011/27/2020 10:002
3D4611/25/2020 0:0011/27/2020 10:004
3P4611/25/2020 0:0011/27/2020 10:004
4<2612/21/2021 13:0012/22/2021 23:002
4C2612/21/2021 13:0012/22/2021 23:002
4P2612/21/2021 13:0012/22/2021 23:002
4S2612/21/2021 13:0012/22/2021 23:002
4C2612/21/2021 13:0012/22/2021 23:002
4C2612/21/2021 13:0012/22/2021 23:002
4E2612/21/2021 13:0012/22/2021 23:002
4S2612/21/2021 13:0012/22/2021 23:002
4G4612/21/2021 13:0012/22/2021 23:004
5M269/1/2022 12:009/22/2022 8:302
5D269/1/2022 12:009/22/2022 8:302
5C269/1/2022 12:009/22/2022 8:302
5C269/1/2022 12:009/22/2022 8:302
5P469/1/2022 12:009/22/2022 8:304
5T269/1/2022 12:009/22/2022 8:302
5D269/1/2022 12:009/22/2022 8:302
5C269/1/2022 12:009/22/2022 8:302
5C269/1/2022 12:009/22/2022 8:302
5S269/1/2022 12:009/22/2022 8:302
5R269/1/2022 12:009/22/2022 8:302
5F369/1/2022 12:009/22/2022 8:303
5F269/1/2022 12:009/22/2022 8:302
6G2611/20/2023 12:0011/21/2023 21:002
6S2611/20/2023 12:0011/21/2023 21:002
6S2611/20/2023 12:0011/21/2023 21:002
6S2611/20/2023 12:0011/21/2023 21:002
6S4611/20/2023 12:0011/21/2023 21:004
6G3611/20/2023 12:0011/21/2023 21:003
6C2611/20/2023 12:0011/21/2023 21:002
6C2611/20/2023 12:0011/21/2023 21:002
6C2611/20/2023 12:0011/21/2023 21:002
6C2611/20/2023 12:0011/21/2023 21:002
6E3611/20/2023 12:0011/21/2023 21:003
6A4611/20/2023 12:0011/21/2023 21:004
6D1611/20/2023 12:0011/21/2023 21:001
dharmendars007
Super User
Super User

Hello @AKath_12 , 

 

Since you mentioned that the "average result" is pulled from a dataset with an inactive relationship to the date table, make sure that you activate this relationship within your DAX query when needed. You can use USERRELATIONSHOT() to activate the inactive relationship.

 

Carry Forward Result =
VAR LastValue =
CALCULATE(
MAX('YourDataTable'[Result]),USERELATIONSHIP('YourDateTable'[Date], 'YourDataTable'[Date]),
FILTER(ALL('YourDataTable'),'YourDataTable'[Date] <= MAX('YourDateTable'[Date])))
RETURN
LastValue

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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