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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
arif_tsrm
Helper I
Helper I

Dynamic N-Value (TOPN) for Least Popular Day Calculation

 

I am trying to calculate Least popular day using the following DAX, but I am getting the fixed result ( Friday ) although there is no value ( blank) in friday, I think the result is fixed Friday is  only for that  I am using  fixed N-Value 5, is there any way we can set the N-Value dynamically?

LeastPopularDayOfWk=

FIRSTNONBLANK (
TOPN (
5,
CALCULATETABLE (
VALUES ( DimDayName[DayName] ),
FILTER ( DimWP, DimWP[WP] <> "Remote" )
),
[%Of_Attendance_By_DayForM/LPD]
),
1
)

 

LPD.PNG

 

1 ACCEPTED SOLUTION

Hi @arif_tsrm ,

I do some changes on my DAX codes.

Measure 2 = 
VAR _A =
    MINX (
        FILTER ( 'Table', NOT ( ISBLANK ( 'Table'[Attendance] ) ) ),
        'Table'[Attendance]
    )
RETURN
    LOOKUPVALUE ( 'Table'[DayShort], 'Table'[Attendance], _A )

Then you can see that it will return you the smallest value other than blank.

vyilongmsft_0-1716973772612.png

 

 

 

Best Regards

Yilong Zhou

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

Hi @arif_tsrm ,

I create a table as you mentioned.

vyilongmsft_0-1716428745301.png

Then I create a measure and here is the DAX code.

Measure =
VAR _Lastest =
    CALCULATE ( MAX ( 'Table'[Number] ), ISBLANK ( 'Table'[Attendance] ) )
RETURN
    CALCULATE (
        MAXX ( FILTER ( 'Table', 'Table'[Number] = _Lastest ), 'Table'[DayShort] ),
        ISBLANK ( 'Table'[Attendance] )
    )

Now you can use dynamic N-Value (TOPN) for least popular day.

vyilongmsft_1-1716428950800.png

 

 

 

Best Regards

Yilong Zhou

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

Thanks for your reply , you have created the table is data table but my mentioned table is a visualization , I want to calculate the least popular day based on value of the measure  [%Of_Attendance_By_DayForM/LPD],   if in any days the  [%Of_Attendance_By_DayForM/LPD] is blank then those days we not consider . for this data scenerio the least popular day will be Tuesday and Wednesday ( because the lowest value is 50%) instead of Friday.

Hi @arif_tsrm ,

I do some changes on my DAX codes.

Measure 2 = 
VAR _A =
    MINX (
        FILTER ( 'Table', NOT ( ISBLANK ( 'Table'[Attendance] ) ) ),
        'Table'[Attendance]
    )
RETURN
    LOOKUPVALUE ( 'Table'[DayShort], 'Table'[Attendance], _A )

Then you can see that it will return you the smallest value other than blank.

vyilongmsft_0-1716973772612.png

 

 

 

Best Regards

Yilong Zhou

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

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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