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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
langosh
New Member

Create groups based on differences between two date columns HISTORICALLY

Hi Everyone,

I have an ORDER TABLE as my fact table which have the following sample data:

OrderIDOrderCreatedOrderClosedDaysResolvedOutstandingDays
000110/07/202415/07/202450
000213/05/202416/05/202430
000320/07/2024null 4


The days resolved shows how many days it took to close an order. 
The OutstandingDays shows how many days it is still open. 

 

NOW my problem is I need to create a visual (bar chart) which would show how many days it was opened on the previous days as well. For this I would like to use a calendar table which consists of all the days, weeks, etc... And somehow connect the two so I could make my final grouping based on how many days it WAS opened on that calendar date. 

E.g with orderID "0001": 

 

OrderIDOrderCreatedCalendarDateOutstandingDaysWarning
000110/07/202410/07/20240OK
000110/07/202411/07/20241Needs Checking
000110/07/202412/07/20242LATE


I wonder if you could help me out how should I approach this situation... Thank you in advance! 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @langosh 

Based on your information, I create a sample table.

Then create a new calendar table:

vyohuamsft_0-1722243226537.png

Next, you need to expand the Orders table to include each date between and for each order. You can do this using Power Query. 

Add a custom column with the following formula to create a list of dates

 

= let 
a = List.Dates([OrderCreated], Duration.Days([OrderClosed] - [OrderCreated]) + 1, #duration(1, 0, 0, 0)) 
in if [OrderClosed] = null then null else a 

 

vyohuamsft_1-1722243531045.png

Expand this new column to create a row for each date

vyohuamsft_2-1722243671400.png

Rename the new column to CalendarDate.

Add a calculated column to determine the number of outstanding days for each date

 

 OutstandingDays = DATEDIFF('Order'[OrderCreated], 'Order'[CalendarDate], DAY) 

 

vyohuamsft_3-1722243805605.png

 

Add another calculated colunm:

 

Warning = 
SWITCH(
    TRUE(),
    'Order'[OutstandingDays] = 0, "OK",
    'Order'[OutstandingDays] = 1, "Needs Checking",
    'Order'[OutstandingDays] >= 2, "LATE"
    
)

 

vyohuamsft_0-1722244468400.png

Here is my preview:

vyohuamsft_1-1722244487717.png

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

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

5 REPLIES 5
Anonymous
Not applicable

Hi, @langosh 

Based on your information, I create a sample table.

Then create a new calendar table:

vyohuamsft_0-1722243226537.png

Next, you need to expand the Orders table to include each date between and for each order. You can do this using Power Query. 

Add a custom column with the following formula to create a list of dates

 

= let 
a = List.Dates([OrderCreated], Duration.Days([OrderClosed] - [OrderCreated]) + 1, #duration(1, 0, 0, 0)) 
in if [OrderClosed] = null then null else a 

 

vyohuamsft_1-1722243531045.png

Expand this new column to create a row for each date

vyohuamsft_2-1722243671400.png

Rename the new column to CalendarDate.

Add a calculated column to determine the number of outstanding days for each date

 

 OutstandingDays = DATEDIFF('Order'[OrderCreated], 'Order'[CalendarDate], DAY) 

 

vyohuamsft_3-1722243805605.png

 

Add another calculated colunm:

 

Warning = 
SWITCH(
    TRUE(),
    'Order'[OutstandingDays] = 0, "OK",
    'Order'[OutstandingDays] = 1, "Needs Checking",
    'Order'[OutstandingDays] >= 2, "LATE"
    
)

 

vyohuamsft_0-1722244468400.png

Here is my preview:

vyohuamsft_1-1722244487717.png

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

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

Yes Thank you! 

This is very similar how I solved it in the meantime. 

thank you!

langosh
New Member

Hi,

I'd like to make a historical stacked barchart with the data of all OrderIDs. Divided into Weeks. 

 

OrderIDOrderCreatedCalendarDateOutstandingDaysWarning
000110/07/202410/07/20240OK
000110/07/202411/07/20241Needs Checking
000110/07/202412/07/20242LATE

sry, still not understand the request. 

Is this table the expected output?What do you mean by devided into weeks?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ryan_mayu
Super User
Super User

So you have three tables in your model? what's the expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.