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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.