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

(direct query) creates a group interval from the difference between 2 dates

Hi teams

i have a report connected to PostgreSql using direct query, and i need to create a group based on difference between current time and admision date, comes out like in this visual.

data range pbi.PNG 

 

 

 

 

and this is my data, 

Data PBI.PNG

 

is anyone can help me to solved it?

 

thank you

1 ACCEPTED SOLUTION
Anonymous
Not applicable

hi @V-lianl-msft 

 

sorry for late respond, 
thanks for your help, 

 

But i ran into another problem after implement your way

 

Cap PBI.PNG for workaround, i try creating query script with DATE_PART function in SQL editor

 Thanks for your help btw.

View solution in original post

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

Create a calculated column like this:

group_ = var days = ABS(DATEDIFF(Table_5[date1],Table_5[date2],HOUR))/24
return SWITCH(TRUE(),
0<days&&days<1,"<1 day",
1<days&&days<2,"1-2 days",
">2 days")

V-lianl-msft_0-1607407532136.png

Sample .pbix

 

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

Anonymous
Not applicable

hi @V-lianl-msft 

 

sorry for late respond, 
thanks for your help, 

 

But i ran into another problem after implement your way

 

Cap PBI.PNG for workaround, i try creating query script with DATE_PART function in SQL editor

 Thanks for your help btw.

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.