derikS4M1
derikS4M1

Reputation: 119

How to SUM data based on date filters in PowerBi

My sample CSV data looks like this, So that you can use the same data below:

ID,Project,From,To,Percentage
1,APPLE,01-01-2022,31-03-2022,50
1,MICROSOFT,01-01-2022,15-01-2022,50
1,MICROSOFT,01-02-2022,28-02-2022,50
1,MICROSOFT,01-03-2022,31-03-2022,50
2,ORACLE,01-02-2022,23-06-2022,50
3,APPLE,23-04-2022,23-06-2022,100
1,MICROSOFT,16-01-2022,31-01-2022,50
2,DELL,01-12-2021,01-04-2022,50

I added a new column for which the dax is

CALCULATE(SUM('sample set'[Percentage]), FILTER('sample set', 'sample set'[ID]=EARLIER('sample set'[ID])&&EARLIER('sample set'[From]) <= 'sample set'[To]&&EARLIER('sample set'[To])>='sample set'[From]))

The result is as shown below

enter image description here

My objective is to see if on any date any employee has been allocated for more than 100% in work. As you can see employee id 1 has been allocated 1/Jan/22 to 31/Mar/22 for 50% in APPLE and multiple periods in MICROSOFT for 50% itself but it doesn't for any period is greater than 100%.

But in the first line, the allocated percentage is shown as 250%. It is because the filter criteria meet all the sub-periods for ID 1. but if you really look into it, it is not 100% on any sub-period. So is there a way that I can get a TRUE/FALSE or any output that can help me see if any employee has been allocated for any project during a certain time that the allocated percentage sum is more than 100%?

Upvotes: 0

Views: 2891

Answers (1)

Ryan B.
Ryan B.

Reputation: 3665

(1) Create a calendar table

Create a calendar table that is not associated with your model. The easiest way is to just go into the Modeling ribbon and click 'new table.' The DAX is simple -- if you want to pick your own begin/end dates use CALENDAR() and not CALENDARAUTO() :

dimCalendar = CALENDARAUTO(12)

(2) Create your measure to drive from the calendar table

Total daily percentage = 

CALCULATE(
    SUM(DemoData[Percentage])
    , FILTER (DemoData, MAX('dimCalendar'[Date]) >= DemoData[From] && MIN('dimCalendar'[Date]) <= DemoData[To])
)

set your measure alongside dimCalendar[Date] and [ID] -- or put it in a line chart visual or whatever. You'll be able to quickly see where a line drifts over 100.

(Here I've added a line for ID #1 on Project 'Side-hustle') enter image description here

Upvotes: 1

Related Questions