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
jct999
Advocate II
Advocate II

Conditionnal sum, with conditions between row

Hi All,

 

I have a table with 5 columns :

 

DIMENSION_1 (string)
DIMENSION_2 (string)
DIMENSION_3 (string)
KPI_TYPE (string)

VOLUME (integer)

 

I would like to create a measure that sum VOLUME with the following conditions :

 

For a each underlying tuple (DIMENSION_1, DIMENSION_2, DIMENSION_3) :

 

If VOLUME exists for KPI_TYPE = "TYPE1"
Then add volume for KPI_TYPE = "TYPE_1" to the sum result
Else add volume for KPI_TYPE = "TYPE_2" to the sum result

 

I would say it is like an iterator SUM with conditions between rows ...

 

Could you help me to create such a measure

 

Thanks

6 REPLIES 6
Anonymous
Not applicable

Hi @jct999 ,

Is there anything else you need help with regarding this post? If not, could you please mark the helpful post as Answered? It will help the others in the community who have similar problems to yours to find a solution as soon as possible. Thank you.

Best Regards

VahidDM
Super User
Super User

Hi @jct999 

 

Can you post sample data as text and expected output?
Not enough information to go on;

please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
4. Relation between your tables

Appreciate your Kudos!!
LinkedIn:www.linkedin.com/in/vahid-dm/

Hi VahidDM

 

Thanks for your message
Here's a sample of the table that contains the data :

 

DIMENSION1DIMENSION2DIMENSION3KPI_TYPEVOLUME
A1B2...KT_197
A1B2...KT_2104
A1B1...KT_2108
A1B2...KT_1100
A2B2...KT_299
A1B3...KT_196
A1B3...KT_293
A2B1...KT_1107
A2B1...KT_290
A2B2...KT_2103
A2B1...KT_1102
A2B1...KT_292
A2B3...KT_192
A2B3...KT_288
A1B2...KT_350
...............

 

For a better understanding, I pivot the KPI_TYPE column and color some numbers :

   KPI_TYPE
DIMENSION1DIMENSION2DIMENSION3KT_1KT_2KT_3
A1B2...9710450
A1B1...(empty)108...
A1B2...10099...
A1B3...9693...
A2B1...10790...
A2B2...(empty)103...
A2B1...10292...
A2B3...9288...
..................

 

Considering this reshaped view :
I want my measure to sum all the green values with the following rules : For each rows, sum the value in column KT_1 if it exists, otherwise sum the value in the column KT_2.

 

Obviously, the data could be filtered by the context/user of the dashboard, and all the dimensions could not be displayed in the widgets....

 

Let me know if it is not clear.

 

Best Regards

Anonymous
Not applicable

Hi @jct999 ,

You can create a matrix visual just as shown in below screenshot, please find the attachment for the details.

yingyinr_0-1637634519277.png

If the above one is not what you want, please provide more details of your expected result with calculation logic and special examples. Thank you.

Best Regards

Hi @jct999 

 

Understand your data table is like the Pivot table, so Please try this measure:

Measure=
Var _K1 = SUM(table[KT_1]
Var _K2 = SUM(table[KT_2]
Var _A = addcolumn(Table,"K12",if(isblank(_K1),_K2,_K1))
return
SUMX(_A,[K12])

 

Also, you can add a new column with Dax code to merge KT1 and KT2 and then use that new column:

Code to add a new Column:

Column =
Var _K1 = SUM(table[KT_1]
Var _K2 = SUM(table[KT_2]
return
if(isblank(_K1),_K2,_K1))

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Hi VahidDM,

 

Unfortunatly, my table is not a pivot table.
It is a flat table with 5 columns (DIMENSION1 to 3, KPY_TYPE and VOLUME).
(see first table)


I showed you pivoted data to give you more clear understanding of my need and rules calculation.

Any idea ?

Thanks for your help

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.