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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
froxas
Helper II
Helper II

help with a DAX formula

I have invoices table which connects to transaction table.

I need to calculate two measures per contract:

1. sum of amount (that works fine)

2. sum of amount insured = it is exactly the same as "sum of amount", but it only needs to calculate these invoices where sum of insured is > 0. it means in below example it do not need to include invoice I003 and I009

 

 

froxas_0-1612440055165.png

 
this i do with a formula, but it wont work.
sum of amount insured = CALCULATE([sum of amount], FILTER(invoice, SUM('transaction'[insured]) > 0))

 

here is my sample data:

sample 

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @froxas 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table1:

b1.png

 

Table2:

b2.png

 

You may create a measure as below.

amount insured = 
var tab = 
SUMMARIZE(
    'Table2',
    'Table2'[invoice_number],
    "Sum",
    SUM('Table2'[amount]),
    "Flag",
    var val = 
    SUM('Table2'[insured])
    return
    IF(
        ISBLANK(val),
        0,1
    )
)
return
SUMX(
    FILTER(
        tab,
        [Flag]=1
    ),
    [Sum]
)

 

Result:

b3.png

 

Best Regards

Allan

 

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

6 REPLIES 6
v-alq-msft
Community Support
Community Support

Hi, @froxas 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table1:

b1.png

 

Table2:

b2.png

 

You may create a measure as below.

amount insured = 
var tab = 
SUMMARIZE(
    'Table2',
    'Table2'[invoice_number],
    "Sum",
    SUM('Table2'[amount]),
    "Flag",
    var val = 
    SUM('Table2'[insured])
    return
    IF(
        ISBLANK(val),
        0,1
    )
)
return
SUMX(
    FILTER(
        tab,
        [Flag]=1
    ),
    [Sum]
)

 

Result:

b3.png

 

Best Regards

Allan

 

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

amitchandak
Super User
Super User

@froxas , Try a measure like

 

calculate(sum(Table[amount]), filter(values(Table[invoice_number]), calculate(sum(Table[insure])) >0))

 

or

 

sumx(filter(values(Table[invoice_number]), calculate(sum(Table[insure])) >0),calculate(sum(Table[amount])))

no, value not changing

@froxas , I tried this. Seems to be working. File attached after signature

sum of amount insured = CALCULATE([sum of amount], FILTER(VALUES(invoice[invoice_number]), SUM('transaction'[insured]) > 0))

 

Screenshot 2021-02-04 18.06.31.png

maybe i explained wrong.

 

the result needs to go in the table marked in red.

and the result needs to be "sum of amount" per contract, but only sum these invoices where invoice total "sum of insured" > 0.

 

it means below table: only invoices I001 and I007 has sum of insured >0, therefore their amount needs to be summed only.

then the result needs to be : 

contrac1 - 300

contrac2 - 500

total: 800

 

 

froxas_0-1612442814213.png

 

PC2790
Community Champion
Community Champion

Hi @froxas ,

 

Please try this:

Measure = CALCULATE(SUM('transaction'[amount]),FILTER('transaction',NOT(ISBLANK('transaction'[insured]))))

The result will be something like below:

PC2790_0-1612447772300.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.