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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Dynamic Date diff grouping visualization

Hi All,

I managed to creat two measuser, one that calculates the diffrence in days bettwen the selected report date and clouser date, and grouping PastDue/Upcoming. Based on this PastDue/Upcoming, I would like to build a bar chart with  PastDue/Upcoming on the x-axis and the number of IDs on the y-axis. 

 

DateDiff = DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)
PastDue/Upcoming = SWITCH (

TRUE,

(DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) < -60 , "Past Due 90",

(DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) >= -60 && (DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) < -30, "Past Due 60",

(DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) >= -30 && (DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) <= 0, "Past Due 30",

(DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) > 60 && (DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) <= 90, "Upcoming 90",

(DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) <= 60 && (DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) > 30, "Upcoming 60",

(DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) <= 30 && (DATEDIFF(SELECTEDVALUE(ReportDate[End of Month]), SELECTEDVALUE(IDs[Clouser Date]), DAY)) > 0, "Upcoming 30",

BLANK()

)

 

 

 

1.png2.png3.png4.PNG

I would like to add a pbix file, but as a new user I can't. Hope screanshots and code will be enough.

 

 

Best regards 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Below is my table1:

vxiandatmsft_0-1702605093637.png

Below is my table2:

vxiandatmsft_1-1702605109464.png

The following DAX might work for you:

 

PastDue/Upcoming1 = SWITCH (

TRUE,

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) < -60 , "Past Due 90",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) >= -60 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) < -30, "Past Due 60",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) >= -30 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) <= 0, "Past Due 30",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) > 60 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) <= 90, "Upcoming 90",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) <= 60 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) > 30, "Upcoming 60",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) <= 30 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) > 0, "Upcoming 30",

BLANK()

)

 

you can try to use column.

The final output is shown in the following figure:

vxiandatmsft_2-1702605191414.png

 

Best Regards,

Xianda Tang

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

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

Below is my table1:

vxiandatmsft_0-1702605093637.png

Below is my table2:

vxiandatmsft_1-1702605109464.png

The following DAX might work for you:

 

PastDue/Upcoming1 = SWITCH (

TRUE,

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) < -60 , "Past Due 90",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) >= -60 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) < -30, "Past Due 60",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) >= -30 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) <= 0, "Past Due 30",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) > 60 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) <= 90, "Upcoming 90",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) <= 60 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) > 30, "Upcoming 60",

(DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) <= 30 && (DATEDIFF(SELECTEDVALUE('Table (2)'[End of month]), SELECTEDVALUE('Table'[Clouser Date]), DAY)) > 0, "Upcoming 30",

BLANK()

)

 

you can try to use column.

The final output is shown in the following figure:

vxiandatmsft_2-1702605191414.png

 

Best Regards,

Xianda Tang

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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