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

Consider previous month value if current month value is blank

Hi Friends,

 

I have few blank values for some of the months for some of the names. I want to show previous month value if current month value is blank. so for example in the below snapshot of HOURS SPENT. In March, value for Ankit Gupta is blank, I want to show 9 for March against Ankit Gupta as this is his previous month value.

 

sandeep_sharma_0-1674535691687.png

 

Below is my backend data:

 

sandeep_sharma_1-1674535719148.png

 

Please help

 

Great thanks in advance!

1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @sandeep_sharma ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1674630317734.png

2. create a measure with below dax formula

Measure =
VAR cur_name =
    SELECTEDVALUE ( 'Table'[Name] )
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Date] )
VAR max_date =
    MAXX (
        FILTER ( ALL ( 'Table' ), 'Table'[Date] < cur_date && 'Table'[Name] = cur_name ),
        [Date]
    )
VAR _val =
    CALCULATE (
        MAX ( 'Table'[Hours Spent] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] = cur_date && 'Table'[Name] = cur_name )
    )
VAR _val2 =
    CALCULATE (
        MAX ( 'Table'[Hours Spent] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] = max_date && 'Table'[Name] = cur_name )
    )
RETURN
    IF ( ISBLANK ( _val ), _val2, _val )

3. add a matrix visual with fields and measure

vbinbinyumsft_1-1674630402578.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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

3 REPLIES 3
statewideboy111
New Member

Hi, 

Thanks for the solution !

I am kind of facing with similar problem. In my case if the if a person does not have any hours recorded against him in any particular month his name is skipped from that month. To encounter the issue I have created two databases. First database contains all the months and second data contains all the names. These two databases are connected to the master sheet. Lets consider the master sheet same as what sandeep_Sharma has provided.

How can i write a DAX to overcome the issue ?

v-binbinyu-msft
Community Support
Community Support

Hi @sandeep_sharma ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1674630317734.png

2. create a measure with below dax formula

Measure =
VAR cur_name =
    SELECTEDVALUE ( 'Table'[Name] )
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Date] )
VAR max_date =
    MAXX (
        FILTER ( ALL ( 'Table' ), 'Table'[Date] < cur_date && 'Table'[Name] = cur_name ),
        [Date]
    )
VAR _val =
    CALCULATE (
        MAX ( 'Table'[Hours Spent] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] = cur_date && 'Table'[Name] = cur_name )
    )
VAR _val2 =
    CALCULATE (
        MAX ( 'Table'[Hours Spent] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] = max_date && 'Table'[Name] = cur_name )
    )
RETURN
    IF ( ISBLANK ( _val ), _val2, _val )

3. add a matrix visual with fields and measure

vbinbinyumsft_1-1674630402578.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Would it be possible to also add the value of April for name B and C. For this case it would have the take the value of last available value which for this case would be Feb value. 

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.