Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi all I have a table with 2 types of capacity in it and for every record a startdate and enddate. Some dummy data is here:
As you can see there is capacity for a costcenter or capacity for a group. A group is a lower level than a costcenter. This all is based on a very simple starschema.
Now I'm creating measures to show the correct amount of capacity for groups and costcenters. My measures are defined as follows:
CC Capacity =
VAR CurDate = SELECTEDVALUE('Date'[Date])
VAR x = SUMX('Date', MAXX(FILTER(Capacity, NOT(ISBLANK(Capacity[CapacityCC])) && CurDate < Capacity[Enddate] && CurDate >= Capacity[Startdate]), SUM(Capacity[CapacityCC])))
RETURN x
and
Group Capacity =
VAR CurDate = SELECTEDVALUE('Date'[Date])
VAR x = SUMX('Date', MAXX(FILTER(Capacity, NOT(ISBLANK(Capacity[CapacityGroup])) && CurDate < Capacity[Enddate] && CurDate >= Capacity[Startdate]), SUM(Capacity[CapacityGroup])))
RETURN x
But what's wrong here is the output 🤣
I have some examples.
Problem 1
Example 1 is selecting 1 specific data (i.e. 2 february 2021) which is giving me the incorrect amount because it's summing all the records that apply, not only the one that should be active based on there start- and enddate.
38 is the result of 18 + 20 while it should be only 18. And 62 is the sum of 30 and 32 instead of just 30.
Problem 2
Problem 2 is when you don't select 1 specific date but a month it's not showing anything. While I should expect the last empty value for that specific month/group/cc.
Is there a dax-guru here to help me out?
File with my example data and all relevant dimensions can be found here.
Solved! Go to Solution.
You can use
CC Capacity copy =
VAR CurDate = MAX( 'Date'[Date] )
VAR x =
CALCULATE(
SUM( 'Capacity'[CapacityCC] ),
NOT ISBLANK( 'Capacity'[CapacityCC] )
&& CurDate < 'Capacity'[Enddate]
&& CurDate >= 'Capacity'[Startdate]
)
RETURN
x
Group Capacity copy =
VAR CurDate = MAX( 'Date'[Date] )
VAR x =
CALCULATE(
SUM( 'Capacity'[CapacityGroup] ),
NOT ISBLANK( 'Capacity'[CapacityGroup] )
&& CurDate < 'Capacity'[Enddate]
&& CurDate >= 'Capacity'[Startdate]
)
RETURN
x
And if I have an additional wish; I also want to see the numbers for a month where a record stops as well? So by example the line with enddate 25-12-2023 must be visible in december 2023 as well. I've tried some things but for the situation where a new line follows up with start 26-12-2023 I go double...
You can use
CC Capacity copy =
VAR CurDate = MAX( 'Date'[Date] )
VAR x =
CALCULATE(
SUM( 'Capacity'[CapacityCC] ),
NOT ISBLANK( 'Capacity'[CapacityCC] )
&& CurDate < 'Capacity'[Enddate]
&& CurDate >= 'Capacity'[Startdate]
)
RETURN
x
Group Capacity copy =
VAR CurDate = MAX( 'Date'[Date] )
VAR x =
CALCULATE(
SUM( 'Capacity'[CapacityGroup] ),
NOT ISBLANK( 'Capacity'[CapacityGroup] )
&& CurDate < 'Capacity'[Enddate]
&& CurDate >= 'Capacity'[Startdate]
)
RETURN
x
User | Count |
---|---|
25 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
30 | |
13 | |
11 | |
9 | |
6 |