cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Group data based on days difference

Hi Guys,

 

I have some data with date fields.

 

What I want to do is get the difference between these 2 days and group it under grouping table based on the number of days.

And the result should be how many orders are there for each group based on the number of days difference.


Answer should looks like this

 

 

kazun909_0-1635315290071.png

 

 

Here is the file.
https://drive.google.com/file/d/1EY1GrBHieyd3XOpWvtWzGwiYqAmrkNfC/view?usp=sharing

1 ACCEPTED SOLUTION

Please check this.

Delay Hours =
var __minval =
SELECTEDVALUE('Grouping'[Min])
var __maxval =
SELECTEDVALUE('Grouping'[Max])
var __datatable =
CALCULATETABLE(
'Data',
'Data'[Plan Vs Actual] = "Delayed"
)
var __answer =
CALCULATE(
COUNT('Data'[Order Number]),
FILTER(
'Data',
'Data'[Column1] >= __minval &&
'Data'[Column1] <= __maxval
),__datatable
)
return
__answer

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

This is the code I am Trying

Delay Hours =
var __minval =
SELECTEDVALUE(Grouping[Min])
var __maxval =
SELECTEDVALUE(Grouping[Max])
var __datediff =
SELECTEDVALUE(Data[Column1])
var __answer =
CALCULATE(
COUNT(Data[Order Number]),
FILTER(
Data,
Data[Plan Vs Actual] = "Delayed"
),
FILTER(
Data,
COUNTROWS(
FILTER(
Grouping,
__datediff>__minval &&
__datediff< __maxval
)
)
)
)
return
__answer

Try this this should give the correct result.

Delay Hours =
var __minval =
SELECTEDVALUE('Grouping'[Min])
var __maxval =
SELECTEDVALUE('Grouping'[Max])
var __datediff =
SELECTEDVALUE('Data'[Column1])
var __datatable =
CALCULATETABLE(
'Data',
'Data'[Plan Vs Actual] = "Delayed"
)
var __answer =
CALCULATE(
COUNT('Data'[Order Number]),
FILTER(
'Data',
__datediff > __minval &&
__datediff < __maxval
),__datatable
)
return
__answer
Anonymous
Not applicable

Not giving the expected Answer.

Please check this.

Delay Hours =
var __minval =
SELECTEDVALUE('Grouping'[Min])
var __maxval =
SELECTEDVALUE('Grouping'[Max])
var __datatable =
CALCULATETABLE(
'Data',
'Data'[Plan Vs Actual] = "Delayed"
)
var __answer =
CALCULATE(
COUNT('Data'[Order Number]),
FILTER(
'Data',
'Data'[Column1] >= __minval &&
'Data'[Column1] <= __maxval
),__datatable
)
return
__answer

View solution in original post

Anonymous
Not applicable

Awesome 😀 Thanks a heap.

Helpful resources

Announcements
Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Top Solution Authors