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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
dandreev
Helper I
Helper I

Create a matrix in hh:mm format

Hi,
I have a table with 3 columns: Year Month, Specialty, Duration (in seconds)

YearMonthSpecialtyDuration
11/1/2023 0:00AA2820
11/1/2023 0:00AA3960
11/1/2023 0:00AA4200
11/1/2023 0:00AA4620
12/1/2023 0:00AA1680
12/1/2023 0:00AA3420
12/1/2023 0:00AA3600
12/1/2023 0:00AA5460
11/1/2023 0:00BB480
11/1/2023 0:00BB660
11/1/2023 0:00BB720
11/1/2023 0:00BB780
11/1/2023 0:00BB960
11/1/2023 0:00CC1020
11/1/2023 0:00CC1080
11/1/2023 0:00CC1140
11/1/2023 0:00CC1200
11/1/2023 0:00CC1260
11/1/2023 0:00CC1320
11/1/2023 0:00CC1500
11/1/2023 0:00CC1680
11/1/2023 0:00CC1860

 

 

I am trying to to create a matrix like that with values in hh:mm format

SpecialtyNov 2023Dec 2023Avg durationMonth  
vs Avg Var
Total
AA156001416014880-72026760
BB360003600-36003600
CC120601000011030-103022060

 

Thank you in advance!

 

2 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

Here is an example of a duration measure.

The first measure is just the sum of seconds.

Duration Seconds = SUM ( YourTable[Duration] )

 

The second measure uses the first to calcuation the time and format it.

Formatted Duration = 
VAR _Seconds = [Duration Seconds]
VAR _Minutes = INT ( DIVIDE ( _Seconds, 60 ) )
VAR _RemainingSeconds = MOD ( _Seconds, 60 )
VAR _Hours = INT ( DIVIDE ( _Minutes, 60 ) )
VAR _RemainingMinutes = MOD ( _Minutes, 60 )

RETURN
    IF (
        NOT ISBLANK ( _Seconds ),
            FORMAT ( _Hours, "00" ) & ":" & 
            FORMAT ( _RemainingMinutes, "00" ) & ":" & 
            FORMAT ( _RemainingSeconds, "00" )
    )

 

View solution in original post

Anonymous
Not applicable

Hi  @dandreev ,

 

Here are the steps you can follow:

1. Create calculated column.

Month_Year =
FORMAT('Table'[YearMonth],"mmm")&" "&YEAR('Table'[YearMonth])

vyangliumsft_0-1707287110544.png

2. Create calculated table.

Test =
SUMMARIZE('Table','Table'[Specialty],'Table'[Month_Year],
"Duration",SUMX(FILTER(ALL('Table'),'Table'[Specialty]=EARLIER('Table'[Specialty])&&'Table'[Month_Year]=EARLIER('Table'[Month_Year])),[Duration]))

vyangliumsft_1-1707287110545.png

Table 2 =
var _table1=
SUMMARIZE(
    'Test','Test'[Specialty],
    "Month_Year","Avg duration",
    "Duration",AVERAGEX(FILTER(ALL('Test'),'Test'[Specialty]=EARLIER('Test'[Specialty])),[Duration]))
var _table2=
SUMMARIZE(
    'Test','Test'[Specialty],
    "Month_Year","Month vs Avg Var",
    "Duration",
    SUMX(FILTER(ALL('Test'),'Test'[Specialty]=EARLIER('Test'[Specialty])&&
    'Test'[Month_Year]=
    MAXX(FILTER(ALL('Table'),'Table'[YearMonth]=MAX('Table'[YearMonth])),[Month_Year])),[Duration])
    -
    AVERAGEX(FILTER(ALL('Test'),'Test'[Specialty]=EARLIER('Test'[Specialty])),[Duration]))
RETURN
UNION(
    'Test',_table1,_table2
)

vyangliumsft_2-1707287140096.png

vyangliumsft_3-1707287140098.png

As far as I know, Power BI's default sorting is based on alphabetical order, so it's not the effect you're looking for, we need to go and create a new table to do the sorting

Sort_Table =
var _table1=
 DISTINCT('Table 2'[Month_Year])
return
ADDCOLUMNS(
    _table1,"Index",
    SWITCH(
    TRUE(),
    [Month_Year]="Nov 2023",1,
    [Month_Year]="Dec 2023",2,
    [Month_Year]="Avg duration",3,
    [Month_Year]="Month vs Avg Var",4))

vyangliumsft_4-1707287218781.png

3. Select [Month_Year] – Column tools – Sort by column – [lndex].

vyangliumsft_5-1707287218784.png

4. Connecting tables to each other.

vyangliumsft_6-1707287260704.png

 

5. Result:

vyangliumsft_7-1707287260708.png

Best Regards,

Liu Yang

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

5 REPLIES 5
Anonymous
Not applicable

Hi  @dandreev ,

 

Here are the steps you can follow:

1. Create calculated column.

Month_Year =
FORMAT('Table'[YearMonth],"mmm")&" "&YEAR('Table'[YearMonth])

vyangliumsft_0-1707287110544.png

2. Create calculated table.

Test =
SUMMARIZE('Table','Table'[Specialty],'Table'[Month_Year],
"Duration",SUMX(FILTER(ALL('Table'),'Table'[Specialty]=EARLIER('Table'[Specialty])&&'Table'[Month_Year]=EARLIER('Table'[Month_Year])),[Duration]))

vyangliumsft_1-1707287110545.png

Table 2 =
var _table1=
SUMMARIZE(
    'Test','Test'[Specialty],
    "Month_Year","Avg duration",
    "Duration",AVERAGEX(FILTER(ALL('Test'),'Test'[Specialty]=EARLIER('Test'[Specialty])),[Duration]))
var _table2=
SUMMARIZE(
    'Test','Test'[Specialty],
    "Month_Year","Month vs Avg Var",
    "Duration",
    SUMX(FILTER(ALL('Test'),'Test'[Specialty]=EARLIER('Test'[Specialty])&&
    'Test'[Month_Year]=
    MAXX(FILTER(ALL('Table'),'Table'[YearMonth]=MAX('Table'[YearMonth])),[Month_Year])),[Duration])
    -
    AVERAGEX(FILTER(ALL('Test'),'Test'[Specialty]=EARLIER('Test'[Specialty])),[Duration]))
RETURN
UNION(
    'Test',_table1,_table2
)

vyangliumsft_2-1707287140096.png

vyangliumsft_3-1707287140098.png

As far as I know, Power BI's default sorting is based on alphabetical order, so it's not the effect you're looking for, we need to go and create a new table to do the sorting

Sort_Table =
var _table1=
 DISTINCT('Table 2'[Month_Year])
return
ADDCOLUMNS(
    _table1,"Index",
    SWITCH(
    TRUE(),
    [Month_Year]="Nov 2023",1,
    [Month_Year]="Dec 2023",2,
    [Month_Year]="Avg duration",3,
    [Month_Year]="Month vs Avg Var",4))

vyangliumsft_4-1707287218781.png

3. Select [Month_Year] – Column tools – Sort by column – [lndex].

vyangliumsft_5-1707287218784.png

4. Connecting tables to each other.

vyangliumsft_6-1707287260704.png

 

5. Result:

vyangliumsft_7-1707287260708.png

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

@Anonymous I can't thank you enough! I was breaking my head how to do it.

jdbuchanan71
Super User
Super User

Here is an example of a duration measure.

The first measure is just the sum of seconds.

Duration Seconds = SUM ( YourTable[Duration] )

 

The second measure uses the first to calcuation the time and format it.

Formatted Duration = 
VAR _Seconds = [Duration Seconds]
VAR _Minutes = INT ( DIVIDE ( _Seconds, 60 ) )
VAR _RemainingSeconds = MOD ( _Seconds, 60 )
VAR _Hours = INT ( DIVIDE ( _Minutes, 60 ) )
VAR _RemainingMinutes = MOD ( _Minutes, 60 )

RETURN
    IF (
        NOT ISBLANK ( _Seconds ),
            FORMAT ( _Hours, "00" ) & ":" & 
            FORMAT ( _RemainingMinutes, "00" ) & ":" & 
            FORMAT ( _RemainingSeconds, "00" )
    )

 

Thanks so much jdbuchanan71, this helped me out greatly!

@jdbuchanan71  Your solution works really good. I think it is very clever.
Thank you, very much!
I found an article that is explaining some other points of time converting.
https://www.mssqltips.com/sqlservertip/7061/calculate-date-difference-power-bi-dax-datediff/

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors