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
Anonymous
Not applicable

find sum of total from calculated column

Hi

 

How to find the sum of total from the calculated columns ?

 

Capture17.PNG

 

Can you please assist ?

 

Thanks

kunuthuri

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

I have made a sample to format the total hours with the formula below.

 

 

foramt total hour =
VAR h =
    HOUR ( 'Table'[total hour] )
VAR m =
    MINUTE ( 'Table'[total hour] )
VAR s =
    SECOND ( 'Table'[total hour] )
RETURN
    SWITCH (
    TRUE (),
    h=0&&m=0&&s=0,"0",
    h=0&&m>0&&s>0,m&"m"&s&"s",
    h=0&&m>0&&s=0,m&"m",
    h=0&&m=0&&s>0,s&"s",
    h>=1&&m>=1&&s>=1,h&"hr"&m&"m"&s&"s",
    h>=1&&m=0&&s=0,h&"hrs",
    h>=1&&m>0&&s>0,h&"hr"&s&"s",
    h>=1&&m>=1&&s=0,h&"hr"&m&"m"
)

Here is the result.

 

format.PNG

For the measure of total hour, you could refer to my first reply.

 

More details, you could have a view of my test pbix file attached below.

 

Best regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

1. Create the calculated colum to calculate the difference of time.

 

hours = 'Table'[End_date]-'Table'[Start_date]

If you want to get the fomat, you could try the formula below.

 

format =
VAR allseconds =
    DATEDIFF ( [Start_date], [End_date], SECOND )
VAR hours =
    MOD ( INT ( allseconds / 60 / 60 ), 24 )
VAR minutes =
    MOD ( INT ( allseconds / 60 ), 60 )
VAR seconds =
    MOD ( allseconds, 60 )
RETURN
    IF (
        AND ( hours >= 1, minutes > 0 ),
        hours & "hr "
            & minutes
            & "mins ",
        IF (
            AND ( hours > 1, minutes = 0 ),
            hours & "hrs",
            IF ( AND ( hours = 0, minutes > 0 ), minutes & "mins" )
        )
    )

hours.PNG

 

2. Create the measure to calculate total hours

 

Measure = CALCULATE(SUM('Table'[hours]))

If you also need the format, you could refer to the formula with if function above.

 

Here is the output.

 

total hours.PNG

 

You also could have a reference of the attachment.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi Cherry,

 

thanks to reply,

 

may i know query "format" is which data type?

 

because when i executed the query and measure is working fine, and once i drag it in to any widget, it is showing below error.

 

Capture10.PNG

 

thanks

kunuthuri 

Anonymous
Not applicable

Hi

 

When i drag the measure

 

meas field = calculate(sum(table[difference hours]))

 

in to "Card" visual , it is showing below error.

 

Capture18.PNG

 

Hi @Anonymous,

 

If you use farmat, the value should be a text type.

 

If you want to show the hours with format, you could calculate the totals hours with sum, then use if or switch function to format the values. 

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi

 

can you please provide example to if or switch function format values?

 

Thanks

Kunuthuri

Hi @Anonymous,

 

I have made a sample to format the total hours with the formula below.

 

 

foramt total hour =
VAR h =
    HOUR ( 'Table'[total hour] )
VAR m =
    MINUTE ( 'Table'[total hour] )
VAR s =
    SECOND ( 'Table'[total hour] )
RETURN
    SWITCH (
    TRUE (),
    h=0&&m=0&&s=0,"0",
    h=0&&m>0&&s>0,m&"m"&s&"s",
    h=0&&m>0&&s=0,m&"m",
    h=0&&m=0&&s>0,s&"s",
    h>=1&&m>=1&&s>=1,h&"hr"&m&"m"&s&"s",
    h>=1&&m=0&&s=0,h&"hrs",
    h>=1&&m>0&&s>0,h&"hr"&s&"s",
    h>=1&&m>=1&&s=0,h&"hr"&m&"m"
)

Here is the result.

 

format.PNG

For the measure of total hour, you could refer to my first reply.

 

More details, you could have a view of my test pbix file attached below.

 

Best regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.