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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Sri57
Frequent Visitor

retrieve latest non blank value if balnk value is selected

I have a table Test with the columns Name, Rating, and Year. I'm using a Year slicer. If I select the value 2023/24 from the slicer, then I should get the count of records from that year. If there is no data for 2023/24, it should check for the previous year, 2022/23. If there is also no data for 2022/23, it should check for 2021/22, and so on, until it finds data, and get the count of records for the selection of 2023/24.
I tried to implement the logic, but I failed to get it exactly right. For example, when I select 2023/24 and there is no data for it, we get no records. Instead, the measure needs to retrieve the count of records for 2022/23.
I have attached the sameple pbix file
https://www.dropbox.com/scl/fi/304a4rxdnmsb96ndgri5m/test1.pbix?rlkey=cv14d4zsqbsjp0m22y89h040o&st=d...

TIA

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

Hi @Sri57@aduguid,

Thank you for your prompt reply!

To meet your requirements, its necessary to use a name slicer to replace the name filter in table visual.

vyajiewanmsft_0-1719308943628.png

Then we need to add the Fiscal Year slicer from another table: Calendar to avoid blank value result.

vyajiewanmsft_1-1719308943631.png

 

Lastly, create a new measure in Audit table and drag the measure in visual filter to control how visual display latest non blank value:

 

 

Measure = 
var _slicerYear=SELECTEDVALUE('Calendar'[Fiscal Year])
var _FilterCount=COUNTROWS(FILTER(ALLSELECTED('Audit'),[FISCAL_YEAR]=_slicerYear))
var _beforeYear=MAXX(FILTER(ALLSELECTED('Audit'),[FISCAL_YEAR]<=_slicerYear),[FISCAL_YEAR])
RETURN SWITCH(TRUE(),
ISFILTERED('Calendar'[Fiscal Year])=FALSE(),1,
_FilterCount=BLANK() && MAX('Audit'[FISCAL_YEAR])=_beforeYear,1,
_FilterCount <> BLANK() && MAX('Audit'[FISCAL_YEAR])= _slicerYear,1,0)

 

 

vyajiewanmsft_0-1719309342757.png

Result for your reference:

vyajiewanmsft_1-1719309368661.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best regards,

Joyce

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

2 REPLIES 2
v-yajiewan-msft
Community Support
Community Support

Hi @Sri57@aduguid,

Thank you for your prompt reply!

To meet your requirements, its necessary to use a name slicer to replace the name filter in table visual.

vyajiewanmsft_0-1719308943628.png

Then we need to add the Fiscal Year slicer from another table: Calendar to avoid blank value result.

vyajiewanmsft_1-1719308943631.png

 

Lastly, create a new measure in Audit table and drag the measure in visual filter to control how visual display latest non blank value:

 

 

Measure = 
var _slicerYear=SELECTEDVALUE('Calendar'[Fiscal Year])
var _FilterCount=COUNTROWS(FILTER(ALLSELECTED('Audit'),[FISCAL_YEAR]=_slicerYear))
var _beforeYear=MAXX(FILTER(ALLSELECTED('Audit'),[FISCAL_YEAR]<=_slicerYear),[FISCAL_YEAR])
RETURN SWITCH(TRUE(),
ISFILTERED('Calendar'[Fiscal Year])=FALSE(),1,
_FilterCount=BLANK() && MAX('Audit'[FISCAL_YEAR])=_beforeYear,1,
_FilterCount <> BLANK() && MAX('Audit'[FISCAL_YEAR])= _slicerYear,1,0)

 

 

vyajiewanmsft_0-1719309342757.png

Result for your reference:

vyajiewanmsft_1-1719309368661.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best regards,

Joyce

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

aduguid
Super User
Super User

Give this one a try. 

Count Records = 
VAR SelectedYear = MAX('Calendar'[Year])
VAR CheckYear = 
    CALCULATE(
        MAX('Test'[Year]),
        FILTER(
            'Test',
            'Test'[Year] <= SelectedYear
        )
    )
VAR ResultCount = 
    CALCULATE(
        COUNTROWS('Test'),
        FILTER(
            'Test',
            'Test'[Year] = CheckYear
        )
    )
RETURN
    ResultCount

 

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

October NL Carousel

Fabric Community Update - October 2024

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

Top Solution Authors