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
Anonymous
Not applicable

DAX for Dynamic Slicing TOP N by GROUP

I am struggling with a DAX measure and was hoping to get some help.


I have an Application table with Application Number, Status Change and Date/Time of Status Change:

ApplicationNumberStatusStatus DateTime
10000001Application Received1/11/2019 14:03
10000001Under Review12/11/2019 14:27
10000001Pending Approval14/11/2019 14:39
10000001Approved18/11/2019 14:53
10000002Application Received30/11/2019 17:02
10000002Under Review6/12/2019 13:33
10000002On Hold7/12/2019 14:31
10000002Pending Approval9/12/2019 14:43
10000002Approved11/12/2019 14:43


I would like to implement a timeline slicer, and based on the time range of the slicer, retrieve a count of the number of applications based on the latest status of the application within the timeline. So if I set the timeline between 1st Nov and 30th Nov I expect to see the following:

StatusCount of Application
Approved1
Application Received1


Where as if I were to set the timeline between 1st Nov and 31st Dec I expect:

StatusCount of Application
Approved2


I have found a DAX measure that almost worked but it does not respond to the timeline slicer correctly. It calculates the rank (of the time of update) for every application, retrieves the top rank (latest update), and then gets filtered by the time slicer. I would like the measure to be filtered first before the rank gets calculated and so on.

CountUpdated =
    COUNTROWS (
        FILTER (
            'Application',
            RANKX (
                CALCULATETABLE (
                    'Application',
                    ALLEXCEPT ( 'Application', 'Application'[applicationnumber] )
                ),
                'Application'[applicationdatetime],
                ,
                DESC,
                DENSE
            ) = 1
        )
    )
Any help would be much appreciated!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi AC,

"table[ApplicationNumber]= [Max_ID] && table[Status DateTime]= ([max_date]) "
DAX did not allow me to reference table[Status DateTime] following the SUMMARIZE, with the error "A single value for column 'Status Date Time' in table.. cannot be determined".

But also, I managed to arrived at this solution which seemed to work:
CountUpdated =
VAR MaxDate =
    MAX ( Application[applicationdatetime] )
VAR MinDate =
    MIN ( Application[applicationdatetime] )
VAR latestupdate =
    COUNTROWS (
        FILTER (
            'Application',
            RANKX (
                CALCULATETABLE (
                    'Application',
                    ALLEXCEPT ( 'Application', 'Application'[applicationnumber] ),
                    Application[applicationdatetime] >= MinDate
                        && Application[applicationdatetime] <= MaxDate
                ),
                'Application'[applicationdatetime],
                ,
                DESC,
                DENSE
            ) = 1
        )
    )
RETURN
    latestupdate

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

Try like this

Total value = Calculate(
    count(table[ApplicationNumber]),
    FILTER(   
            SUMMARIZE(
                table,
                table[ApplicationNumber],
				"max_date",
				MAX( 'table'[Status DateTime]),
                "Max_ID", max(table[ApplicationNumber])
            ),
            
                    table[ApplicationNumber]= [Max_ID] && table[Status DateTime]= ([max_date]) 
			)
                
          
    )

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Anonymous
Not applicable

Hi AC,

"table[ApplicationNumber]= [Max_ID] && table[Status DateTime]= ([max_date]) "
DAX did not allow me to reference table[Status DateTime] following the SUMMARIZE, with the error "A single value for column 'Status Date Time' in table.. cannot be determined".

But also, I managed to arrived at this solution which seemed to work:
CountUpdated =
VAR MaxDate =
    MAX ( Application[applicationdatetime] )
VAR MinDate =
    MIN ( Application[applicationdatetime] )
VAR latestupdate =
    COUNTROWS (
        FILTER (
            'Application',
            RANKX (
                CALCULATETABLE (
                    'Application',
                    ALLEXCEPT ( 'Application', 'Application'[applicationnumber] ),
                    Application[applicationdatetime] >= MinDate
                        && Application[applicationdatetime] <= MaxDate
                ),
                'Application'[applicationdatetime],
                ,
                DESC,
                DENSE
            ) = 1
        )
    )
RETURN
    latestupdate

@Anonymous, Thanks for the update. If the solution you have posted is working. Please mark that as a solution, so that others can get benefited having a similar problem.

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.