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 grouping consecutive days

Problem_grouping_consecutive_days.jpg

Hello everyone,

the last days I tried to find a formula to group the consecutive days. I want to add a column with the values, which a shown on the right side in the picture. I tried several formulas with rankx, but I didn't find the right way.

I would be very glad, if you can help me with this problem.

 

Best regards

2 ACCEPTED SOLUTIONS
v-lili6-msft
Community Support
Community Support

Hi@ Friedrich

After my research ,You can try to do these follow my steps like below:

Step 1:

Sort Date ascending

And then Duplicate table

4.png

 

Step 2:

Add index column for two table

Basic table start from 1 and increment is  1

Duplicate table start from 0 and increment is  1

5.png

 

Step 3:

Merge two table

6.png

Step 4:

Expand the table

7.png

Step 5:

Add column:

Select your date column ->Add Column ->Date ->Subtract Days

8.png

Step 6:

Duplicate the table in current state

9.png

Step 7:

Filter the table which values is ‘1’

10.png11.png

Step 8:

Add index column start from 1 and increment is  1

12.png

Step 9:

Merge second duplicate with basic table

14.png

Step 10:

Expand the table

15.png

 

Step 11:

Select Table2(5).Index.1 column, Right click Fill->UP

16.png

Step 12:

Remove unnecessary column .

Result:

17.PNG

 

Here is demo , please try it.

PBIX FILE https://www.dropbox.com/s/wsot9lfhq8sunlo/dax%20grouping%20consecutive%20days.pbix?dl=0

DATA FILE https://www.dropbox.com/s/gle4648a4c81kro/example.xlsx?dl=0

 

Best Regards,

Lin

Community Support Team _ Lin
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

Anonymous
Not applicable

Solution Grouping Dates.jpg

Hello everyone,

tank you very much for your solution.

I want a solution only with Dax in Power pivot.

I had found a way.

The measures are:

Index := RANKX(FILTER('tab_Beispiel_gruppierung_Datum';'tab_Beispiel_gruppierung_Datum'[FID]=EARLIER('tab_Beispiel_gruppierung_Datum'[FID]));'tab_Beispiel_gruppierung_Datum'[Datum];;ASC;Dense)

Date2 shift :=MINX(FILTER('tab_Beispiel_gruppierung_Datum';'tab_Beispiel_gruppierung_Datum'[FID]=EARLIER('tab_Beispiel_gruppierung_Datum'[FID]) && 'tab_Beispiel_gruppierung_Datum'[Datum]>EARLIER('tab_Beispiel_gruppierung_Datum'[Datum]));'tab_Beispiel_gruppierung_Datum'[Datum])

substraction Date := DATEDIFF('tab_Beispiel_gruppierung_Datum'[Datum];'tab_Beispiel_gruppierung_Datum'[Date2 shift];DAY)

Index2 :=IF([substraction Date]>1;1;0)

Index2 * Date :=[Index2]*[Datum]

Index3 :=RANKX('tab_Beispiel_gruppierung_Datum';[Index2 * Date];;ASC;Dense)

Index3 shift :=MAXX(FILTER('tab_Beispiel_gruppierung_Datum';'tab_Beispiel_gruppierung_Datum'[FID]=EARLIER('tab_Beispiel_gruppierung_Datum'[FID]) && 'tab_Beispiel_gruppierung_Datum'[Index]=EARLIER('tab_Beispiel_gruppierung_Datum'[Index])-1);'tab_Beispiel_gruppierung_Datum'[Index3])

Index4 :=IF([Index3 shift]=1;BLANK();[Index3 shift])

Index6 :=MAXX(FILTER('tab_Beispiel_gruppierung_Datum';'tab_Beispiel_gruppierung_Datum'[FID]=EARLIER('tab_Beispiel_gruppierung_Datum'[FID]) && 'tab_Beispiel_gruppierung_Datum'[Index]<=EARLIER([Index]));'tab_Beispiel_gruppierung_Datum'[Index4])

Index6 replace blank :=IF(ISBLANK([Index6]);1;[Index6])

 

If you find a better way with one or two Rankx formulas, letzt me know it.

Best regards

View solution in original post

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

Hi@ Friedrich

After my research ,You can try to do these follow my steps like below:

Step 1:

Sort Date ascending

And then Duplicate table

4.png

 

Step 2:

Add index column for two table

Basic table start from 1 and increment is  1

Duplicate table start from 0 and increment is  1

5.png

 

Step 3:

Merge two table

6.png

Step 4:

Expand the table

7.png

Step 5:

Add column:

Select your date column ->Add Column ->Date ->Subtract Days

8.png

Step 6:

Duplicate the table in current state

9.png

Step 7:

Filter the table which values is ‘1’

10.png11.png

Step 8:

Add index column start from 1 and increment is  1

12.png

Step 9:

Merge second duplicate with basic table

14.png

Step 10:

Expand the table

15.png

 

Step 11:

Select Table2(5).Index.1 column, Right click Fill->UP

16.png

Step 12:

Remove unnecessary column .

Result:

17.PNG

 

Here is demo , please try it.

PBIX FILE https://www.dropbox.com/s/wsot9lfhq8sunlo/dax%20grouping%20consecutive%20days.pbix?dl=0

DATA FILE https://www.dropbox.com/s/gle4648a4c81kro/example.xlsx?dl=0

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Solution Grouping Dates.jpg

Hello everyone,

tank you very much for your solution.

I want a solution only with Dax in Power pivot.

I had found a way.

The measures are:

Index := RANKX(FILTER('tab_Beispiel_gruppierung_Datum';'tab_Beispiel_gruppierung_Datum'[FID]=EARLIER('tab_Beispiel_gruppierung_Datum'[FID]));'tab_Beispiel_gruppierung_Datum'[Datum];;ASC;Dense)

Date2 shift :=MINX(FILTER('tab_Beispiel_gruppierung_Datum';'tab_Beispiel_gruppierung_Datum'[FID]=EARLIER('tab_Beispiel_gruppierung_Datum'[FID]) && 'tab_Beispiel_gruppierung_Datum'[Datum]>EARLIER('tab_Beispiel_gruppierung_Datum'[Datum]));'tab_Beispiel_gruppierung_Datum'[Datum])

substraction Date := DATEDIFF('tab_Beispiel_gruppierung_Datum'[Datum];'tab_Beispiel_gruppierung_Datum'[Date2 shift];DAY)

Index2 :=IF([substraction Date]>1;1;0)

Index2 * Date :=[Index2]*[Datum]

Index3 :=RANKX('tab_Beispiel_gruppierung_Datum';[Index2 * Date];;ASC;Dense)

Index3 shift :=MAXX(FILTER('tab_Beispiel_gruppierung_Datum';'tab_Beispiel_gruppierung_Datum'[FID]=EARLIER('tab_Beispiel_gruppierung_Datum'[FID]) && 'tab_Beispiel_gruppierung_Datum'[Index]=EARLIER('tab_Beispiel_gruppierung_Datum'[Index])-1);'tab_Beispiel_gruppierung_Datum'[Index3])

Index4 :=IF([Index3 shift]=1;BLANK();[Index3 shift])

Index6 :=MAXX(FILTER('tab_Beispiel_gruppierung_Datum';'tab_Beispiel_gruppierung_Datum'[FID]=EARLIER('tab_Beispiel_gruppierung_Datum'[FID]) && 'tab_Beispiel_gruppierung_Datum'[Index]<=EARLIER([Index]));'tab_Beispiel_gruppierung_Datum'[Index4])

Index6 replace blank :=IF(ISBLANK([Index6]);1;[Index6])

 

If you find a better way with one or two Rankx formulas, letzt me know it.

Best regards

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.