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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SanSan
Frequent Visitor

Total days after if statement

Hello!

 

I can't get this measure working.

 

I have a table that is filter by 2 date slicers. One is the year and one is the period (4 weeks)

 

I have a measure that calculates the total sick days between the two dates in the period.  If startingdate is earlier then startdate of period it should use the start date of the periode. Also if end date of sick is blank then end date of period should be used with a max of 28 days.

Below you see my table and as you can see i have the days for each row but i need to measure the total days. In my table it shows 28 and not the total of all the days.

 

SanSan_0-1655464410273.png

 

This is the measure use. 

Aantal_verzuim_dagen 3 =
VAR CurrentDate = MAX(DimDatum[Datum])
VAR MinVerzuimData = MIN(AFAS_verzuim[Begindatum_-tijd_verzuim])
VAR MaxVerzuimData = MAX(AFAS_verzuim[Einddatum_verzuim])
VAR MAXVerzuimEnd = IF(ISBLANK(MaxVerzuimData),CurrentDate,MaxVerzuimData)
VAR PeriodeDatumMin = FIRSTDATE(DimDatum[Datum])
VAR PeriodeDatumMax = LASTDATE(DimDatum[Datum])
VAR MinVerzuimDataEnd = IF(MinVerzuimData < PeriodeDatumMin, PeriodeDatumMin,MinVerzuimData)
VAR PeriodeMin = SELECTEDVALUE(DimDatum[Datum])

VAR ActiveVerzuimEmp =
CALCULATE(
SUMX(AFAS_verzuim,AFAS_verzuim[Aantal_verzuim_dagen]),
ALL(DimDatum),
DimDatum[Datum] <= MAXVerzuimEnd,
ISBLANK(AFAS_verzuim[Einddatum_verzuim])
|| AFAS_verzuim[Einddatum_verzuim] > MinVerzuimDataEnd
)

VAR boven28 =
SWITCH(TRUE(),
ActiveVerzuimEmp > 28, 28,0,
ActiveVerzuimEmp)

Return
IF(ActiveVerzuimEmp > 28, 28,ActiveVerzuimEmp)


How can i get the total amount of "Aantal_verzuim_dagen 3"?

 
Thank you,
 
San San
4 REPLIES 4
Greg_Deckler
Super User
Super User

@SanSan This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

Hi Greg, Thank you for the reply. I have checked the posts and tried somne but can't get the right total.

 

I have changed the end of the measure to this:

VAR CurrentDate = MAX(DimDatum[Datum])
VAR MinVerzuimData = MIN(AFAS_verzuim[Begindatum_-tijd_verzuim])
VAR MaxVerzuimData = MAX(AFAS_verzuim[Einddatum_verzuim])
VAR MAXVerzuimEnd = IF(ISBLANK(MaxVerzuimData),CurrentDate,MaxVerzuimData)
VAR PeriodeDatumMin = FIRSTDATE(DimDatum[Datum])
VAR PeriodeDatumMax = LASTDATE(DimDatum[Datum])
VAR MinVerzuimDataEnd = IF(MinVerzuimData < PeriodeDatumMin, PeriodeDatumMin,MinVerzuimData)
VAR PeriodeMin = SELECTEDVALUE(DimDatum[Datum])

VAR ActiveVerzuimEmp =
CALCULATE(
SUMX(AFAS_verzuim,AFAS_verzuim[Aantal_verzuim_dagen]),
ALL(DimDatum),
DimDatum[Datum] <= PeriodeDatumMax,
ISBLANK(AFAS_verzuim[Einddatum_verzuim])
|| AFAS_verzuim[Einddatum_verzuim] > PeriodeDatumMin
)
VAR _result =
IF(ActiveVerzuimEmp > 28, 28, ActiveVerzuimEmp)

VAR _table = SUMMARIZE(AFAS_verzuim,AFAS_verzuim[Aantal_verzuim_dagen],"aantallen",_result)

Return
IF(HASONEVALUE(AFAS_verzuim[Aantal_verzuim_dagen]),_result,SUMX(_table,_result))

 

The total that i'm looking for is 430. Somehow it stil skips some amounts see table below:

 

SanSan_0-1655474390737.png

 

Any suggestions to make this work?


Thanks,

 

San San

 

@SanSan It's generally easiest to implement as 2 measures. Get the individual row measure working. Then create the "total" measure that essentially checks to see if it is in an individual row and if so, return the "single" measure. Otherwise, you have to use a SUMMARIZE or GROUPBY or SUMMARIZECOLUMNS to summarize the current in-context table exactly as in the visual, use ADDCOLUMNS to add your "single" measure and then do a SUMX across that table to get the total. Hard to be specific without data, etc.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

 

I have tried with addcolom but somehow got the same result.

 

I have added a table with the data I use. Where Verzuimmelding is the key and you got the startdate, enddate and the count of days. If end_date is blank then end date should be max period enddate. The period is between 25-04-2022 and 22-05-2022. If counted days is > 28 then it should count 28 days. (for date format it is DD-MM-YY)

 

The days should be counted for every verzuimmelding where start_date of verzuimmelding is < then end_date and and end_date of verzuim is > startdate of period and when blank max of period enddate.

 

Could you help me to make this work?


The measure I used:

 

VAR PeriodeDatumMin = FIRSTDATE(Date_dim[Datum])
VAR PeriodeDatumMax = LASTDATE(Date_dim[Datum])

VAR ActiveVerzuimEmp =
CALCULATE(
SUMX('Table','Table'[Count_days]),
ALL(Date_dim),
Date_dim[Datum] <= PeriodeDatumMax,
ISBLANK('Table'[End_date])
|| 'Table'[End_date] > PeriodeDatumMin)
 
VAR _result =
IF(ActiveVerzuimEmp > 28,28,ActiveVerzuimEmp)

VAR _table = SUMMARIZE('Table','Table'[Count_days],"aantallen",_result)
 
Return
CALCULATE(SUMX(ADDCOLUMNS(_table,"Dagen",_result),[Dagen]))

 

VerzuimmeldingStart_date End_date Count_days
14421-04-22 26-04-22 6
1459-09-21   281
14629-12-21 3-01-22 4
15626-04-22 6-05-22 9
1577-06-22 10-06-22 2
15819-08-21   302
15928-09-21   262
1606-10-21   254
1904-03-22   105
1917-03-22 29-04-22 53
20530-03-22 2-04-22 2
20621-02-22 30-05-22 100
2071-04-22   77
2084-04-22 11-04-22 7
2126-04-22 15-04-22 8
2136-04-22 9-04-22 2
2146-04-22 16-04-22 26
2158-04-22   70
21611-04-22 16-04-22 4
21711-04-22 14-04-22 7
22529-04-22 6-06-22 37
2262-05-22 11-05-22 8
22725-04-22 17-05-22 21
2286-05-22 14-05-22 13
2298-05-22 12-05-22 3
2309-05-22 14-05-22 4
2319-05-22   39
2329-05-22   39
23316-05-22 19-05-22 7
23423-05-22 28-05-22 4
23523-05-22 26-05-22 2
23623-05-22 4-06-22 11
2378-06-22 11-06-22 6
2388-06-22 10-06-22 8
2399-06-22   8
24014-06-22   8
27728-02-22   123
31513-04-22 27-04-22 13
31929-04-22 4-05-22 5
32029-04-22 10-05-22 10
3212-05-22 7-05-22 4
3222-05-22   88
3232-05-22 9-05-22 7
3249-05-22 14-05-22 4
3259-05-22 13-05-22 3
32617-05-22 20-05-22 2
33025-05-22   23
33125-05-22 28-05-22 2
33230-05-22 11-06-22 11
33330-05-22   18
33430-05-22 31-05-22 2
33531-05-22 4-06-22 7
3361-06-22 14-06-22 12
3377-06-22 10-06-22 2
3387-06-22   10
3397-06-22 11-06-22 3
3408-06-22 14-06-22 6
34110-06-22 14-06-22 5
34213-06-22   15
34314-06-22   3
3701-03-22   108
3883-05-22 10-05-22 10
38918-05-22 21-05-22 2
39025-05-22 30-05-22 4
39131-05-22   21
39213-06-22   4
39518-01-21   515
39610-05-21 19-05-22 373

 

Thanks,

San San

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.