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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
pjohnson
Frequent Visitor

Calculated column that aggregates over N number of rows

We have a dataset were the row granularity is not fixed. For each widget in the dataset, we can have 1 to N rows of data that describes it. We often create calculated fields in Tableau that aggregate a field over all rows of each widget. Here is a simplistic example:

 

Line # is the widget identifier

Series is the product series for that row of data

Line-Series is the aggregated value

 

Line #SeriesLine-Series
1AA
1AA
2Amulti
2Amulti
2Bmulti
3CC

 

In Tableau, this is a simple Fixed Level Of Detail calculation:

fixed [Line #]: If COUNTD(Series) > 1 then "multi" else max(Series) END 

 

We then take this calculated field and use it like a normal dimension in all aspects of reporting (sum $ by it, use it as a report filtert, etc) in Tableau.

 

How do I do this in Power BI?

 

TIA!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,

I suppose the 'Line-series' field is what you are looking for.

I used the below DAX to generate the calculated column.

Line-Series = 
VAR v_SeriesCnt = CALCULATE
( 
    DISTINCTCOUNT( SeriesData[Series] ), 
    ALLEXCEPT( SeriesData, SeriesData[Line] ) 
 )
 RETURN
 IF( v_SeriesCnt > 1, "Multi", CALCULATE( MAX( SeriesData[Series] ), ALLSELECTED( SeriesData[Series] ) ))

result.PNG

Thanks.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi,

I suppose the 'Line-series' field is what you are looking for.

I used the below DAX to generate the calculated column.

Line-Series = 
VAR v_SeriesCnt = CALCULATE
( 
    DISTINCTCOUNT( SeriesData[Series] ), 
    ALLEXCEPT( SeriesData, SeriesData[Line] ) 
 )
 RETURN
 IF( v_SeriesCnt > 1, "Multi", CALCULATE( MAX( SeriesData[Series] ), ALLSELECTED( SeriesData[Series] ) ))

result.PNG

Thanks.

Helpful resources

Announcements
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.