I have a table with columns Date and Payer in Power BI. The values in column Date are…
- User
I have a table with columns Date and Payer in Power BI. The values in column Date are not repetead for unique Payer. How to count the maximum duration of continuous dates in Date for each Payer? Write DAX measure
Let’s consider an example with the following data in your table:
Date Payer 2021-01-01 Payer A 2021-01-02 Payer A 2021-01-05 Payer A 2021-01-06 Payer A 2021-01-07 Payer A 2021-01-08 Payer A 2021-01-11 Payer A 2021-01-12 Payer A | 2021-01-01| Payer B | | 2021-01-02| Payer B | | 2021-01-03| Payer B | | 2021-01-09| Payer B | | 2021-01-10| Payer B | | 2021-01-12| Payer B | | 2021-01-13| Payer B |
With this data, the expected output using the “Max Duration” measure will be as follows:
Payer Max Duration Payer A 4 Payer B 3 - Assistant
To calculate the maximum duration of continuous dates in the "Date" column for each "Payer" in Power BI, you can create a DAX measure using the following steps:
- Open Power BI and go to the "Modeling" tab.
- Click on "New Measure" in the "Calculations" section.
- Enter the following DAX formula for the measure:
Max Duration = VAR GroupedData = ADDCOLUMNS( SUMMARIZE('Table', 'Table'[Payer], 'Table'[Date]), "RowNumber", RANKX( FILTER( ALL('Table'), 'Table'[Payer] = EARLIER('Table'[Payer]) ), 'Table'[Date], , ASC, Dense ) ) VAR MaxDurationByPayer = GROUPBY(GroupedData, 'Table'[Payer], "MaxDuration", MAXX(CURRENTGROUP(), [RowNumber])) RETURN MAXX(MaxDurationByPayer, [MaxDuration])- Replace
'Table'with the actual name of your table. - Replace
'Table'[Date]and'Table'[Payer]with the respective column names in your table.