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

Sum based on other column values (IF, then...)

Hi,

 

I have the following data:

 

  • Sales data with Quantity, Total Value and Invoiced value 

Problem:

  • I want to create a measure that sums based on the below conditions:
  • If the value in column 'Quantity' or column 'Total value' is >0 then take the value from 'Invoiced value'  
  • If the value in column 'Quantity' or column 'Total value' is 0 then take the value from 'Total value'
  • If the value in column 'Invoiced value' is 'Not invoiced' then take the value from 'Total value'

How can I create this measure?

 

Table with data where the correct sum in this example would be 287. 

 

QuantityTotal valueInvoiced value
0611
01011
5015
01512
1123140
1235
266
097
4110
101
5505
3515
23Not invoiced
45Not invoiced
18Not invoiced
0915
2614
4112
5011
01511

 

carlenb_1-1698831301995.png

 

1 ACCEPTED SOLUTION
carlenb
Advocate II
Advocate II

I managed to solve this myself. Many thanks @some_bih for helping along the way and asking the right questions! 

View solution in original post

8 REPLIES 8
carlenb
Advocate II
Advocate II

I managed to solve this myself. Many thanks @some_bih for helping along the way and asking the right questions! 

carlenb
Advocate II
Advocate II

Edited my latest post with a new table, since I need to consider also local currency. 

some_bih
Super User
Super User

Hi @carlenb there is possible scenario 

If the value in column 'Quantity' =0 and column 'Total value'>0 l(first row example)
If the value in column 'Quantity' >0 and column 'Total value'=0 l(third row example)

 

what to do?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi @some_bih 

 

Thanks, well spotted! See below answers. You can also see the correct values for these scenarios in the screenshot in the thread start (Column E)

 

If the value in column 'Quantity' =0 and column 'Total value'>0 l(first row example) If Quantity = 0 then it would be Total value even if Total value = 0 or >0
If the value in column 'Quantity' >0 and column 'Total value'=0 l(third row example) If quantity > 0 then go for Total value even if Total value is = 0

Hi @carlenb could you please once again check your conditions =0 and >0 could be Invoiced value and total value





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi @some_bih I checked and here are the conditions: 

 

  • If Quantity = 0 then sum Total value
  • If Total value = 0 then sum Total value (which will be 0)
  • If "Not invoiced" in Invoiced value then sum Total value
  • In neither Quantity or Total value = 0 then sum Invoiced value 

There is also one more requirement that popped up: 

  • If there are duplicate rows of order numbers, then pick only the MAX value for that order number 
  • See table updated with order number. So for example, for Order Number "5" the value would be 6 and not 6+6 since there are two rows with order number 5 
QuantityTotal valueInvoiced valueOrder number
06111
010112
50153
015123
11231404
12365
2665
0976
41107
1018
55059
351510
23Not invoiced11
45Not invoiced11
18Not invoiced11
091512
261512
411213
501114
0151114

Hi @carlenb so for condition 

  • In neither Quantity or Total value = 0 then sum Invoiced value  othwerwise Total value?
  • Order number is key-id?




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi @some_bih see below answers  

 

  • In neither Quantity or Total value = 0 then sum Invoiced value  othwerwise Total value? Yes, and if the total value in column 'Invoiced value' is 'Not invoiced' then take the value from 'Total value' 
  • Order number is key-id? In this case yes. There are other columns such as [article number], [purchase order date] and [supplier id] but [order number] will be the key identifier for the sum  

Edit: 

 

One update since yesterday is that I have calculated Total Value in local currency with the below measure. This is something to consider too becuase instead of Total Value I need to use Invoiced value based on the conditions mentioned above. I have updated the table so that this is reflected. The reason for updating is because I realized the problem was more complex than first. 

 

Total Value _ Exchange =
SUMX('Sales 2019-2022',
    'Sales 2019-2022'[Total Value] *
        LOOKUPVALUE('Exchange_currency'[Exchange rate],
        'Exchange_currency'[Date], 'Sales 2019-2022'[Purchase Order Date],
        'Exchange_currency'[Currency], 'Sales 2019-2022'[Crcy]) )
 
Order numberQuantityTotal valueInvoiced valueCurrencyPurchase order date
11611SEK2019-04-02
101011NOK2019-04-03
25015EUR2019-04-04
221512EUR2019-04-05
31123140EUR2019-04-06
30235SEK2019-04-07
4266USD2020-04-02
4197NOK2020-04-03
54110EUR2020-04-04
5101EUR2020-04-05
65505EUR2020-04-06
60515SEK2021-04-07
723Not invoicedUSD2021-04-02
745Not invoicedNOK2021-04-03
818Not invoicedEUR2021-04-04
81915EUR2021-04-05
92614EUR2021-04-06
104112SEK2022-04-07
115011USD2022-04-08
1111511SEK2022-04-09

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.