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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
TimmK
Helper IV
Helper IV

Bar Chart Group By

I have the simple FACT table "Piece" with the columns "Piece Key" and "Duration". A piece key may occur multiple times (as seen in the left table below). Yet, I want to group by "Piece Key" to get the summed duration per piece (as seen in the right table below; 407436 is summed to 60)

 

TimmK_1-1690290336787.png

 

This works fine so far.

 

The DAX code I use for grouping by "Piece Key" is the following:

Duration SUM = 
CALCULATE(
    SUMX(
        SUMMARIZE('Piece', 'Piece'[Piece Key], "SumDuration", SUM('Piece'[Duration])),
        [SumDuration]
    )
)

 

Yet, I want to show the distribution in the sense of frequency per summed duration in a bar chart. But it does not work, I cannot drag & drop my measure with the summed duration by piece key into the x-axis field. How can I do this?

 

I can only use duration for each row, so it counts the value "30" twice, instead of summing it up to "60" and then counting "1".

TimmK_2-1690290389092.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @TimmK ,

 

You need to create a table with data generateseries from 0 to max value (60) for X aixs in column chart.

X aixs = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( 'Piece' ),
        'Piece'[Piece Key],
        "SumDuration", SUM ( 'Piece'[Duration] )
    )
RETURN
    GENERATESERIES ( 0, MAXX ( _SUMMARIZE, [SumDuration] ), 1 )

Measure:

Count = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( 'Piece' ),
        'Piece'[Piece Key],
        "SumDuration", SUM ( 'Piece'[Duration] )
    )
RETURN
    COUNTAX (
        FILTER ( _SUMMARIZE, [SumDuration] = MAX ( 'X aixs'[X aixs] ) ),
        [Piece Key]
    )

Result is as below.

vrzhoumsft_0-1690427619007.png

 

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
Anonymous
Not applicable

Hi @TimmK ,

 

You need to create a table with data generateseries from 0 to max value (60) for X aixs in column chart.

X aixs = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( 'Piece' ),
        'Piece'[Piece Key],
        "SumDuration", SUM ( 'Piece'[Duration] )
    )
RETURN
    GENERATESERIES ( 0, MAXX ( _SUMMARIZE, [SumDuration] ), 1 )

Measure:

Count = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( 'Piece' ),
        'Piece'[Piece Key],
        "SumDuration", SUM ( 'Piece'[Duration] )
    )
RETURN
    COUNTAX (
        FILTER ( _SUMMARIZE, [SumDuration] = MAX ( 'X aixs'[X aixs] ) ),
        [Piece Key]
    )

Result is as below.

vrzhoumsft_0-1690427619007.png

 

Best Regards,
Rico Zhou

 

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

barritown
Super User
Super User

Hello @TimmK,

Why don't you just create an additional table and use its [SUM Duration] column to create the bar chart you need?

Extra Table = SUMMARIZE ( Piece, [Piece Key], "SUM Duration", SUM ( Piece[Duation] ) )

 

barritown_0-1690373506983.png

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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