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
FranciscoJVV
Frequent Visitor

measure with Variable dont show total

Hello, I'm stuck right now with a problem and i have a little guess why is  not working but i dont know so much dax to solve it.

Some days ago i asked help with this https://community.powerbi.com/t5/Desktop/Set-value-to-the-day-after/m-p/919562 and it got solved, when i put the measure on a matrix with dates it works fine, BUT when i use card visualization, it doesnt show me the total when i got night shifts.Captura1.JPGthis is for day shifts, it works fine,Captura2.JPG but you can see in Night shifts it doesnt add ( i know as the result should be the same, but the difference is much bigger than what i calculate) so i put filters on my data and I got the right values, and as far as I could see, it doesnt add me some values

this is the code 

NightShift = 

VAR PreviousDayDate = MAX(HistorialPorTaller[FechaBeginning]) -1

RETURN

SUM(HistorialPorTaller[TimeBefore24]) +

CALCULATE(SUM(HistorialPorTaller[TimeAfter24]); Calendar[Date] = PreviousDayDate)

Total Duration + Night = CALCULATE(SUM(HistorialPorTaller[TotalDuration]);HistorialPorTaller[DayShift]="NO")+[NightShift]

So as far as my knowledge let me think, when i use Total Duration + Night on the card It doesnt add me the TimeAfter24 but when I used it on a matrix it showed me the right values, so i dont know why that happen

 

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

In the Matrix each row is a date and [Total Duration +Nights] is calculated for each day, one by one - except for total row.

In the card there is only one date - day before the last day and this is what is shown. It should also be the same value as in your Matrix total row

If you want to have sum of all days you would need to use SUMX on all values per day, this would also work for single row

EDIT
I actually got another idea, try this (it also works for date ranges):

NightShift =
VAR __CurrentDayDate =
    MAX ( HistorialPorTaller[FechaBeginning] )
RETURN
    SUM ( HistorialPorTaller[TimeBefore24] )
        + CALCULATE (
            SUM ( HistorialPorTaller[TimeAfter24] );
            'Calendar'[Date] < __CurrentDayDate;
            DATEADD ( 'Calendar'[Date]; -1; DAY )
        )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

1 REPLY 1
Stachu
Community Champion
Community Champion

In the Matrix each row is a date and [Total Duration +Nights] is calculated for each day, one by one - except for total row.

In the card there is only one date - day before the last day and this is what is shown. It should also be the same value as in your Matrix total row

If you want to have sum of all days you would need to use SUMX on all values per day, this would also work for single row

EDIT
I actually got another idea, try this (it also works for date ranges):

NightShift =
VAR __CurrentDayDate =
    MAX ( HistorialPorTaller[FechaBeginning] )
RETURN
    SUM ( HistorialPorTaller[TimeBefore24] )
        + CALCULATE (
            SUM ( HistorialPorTaller[TimeAfter24] );
            'Calendar'[Date] < __CurrentDayDate;
            DATEADD ( 'Calendar'[Date]; -1; DAY )
        )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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.