cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ttaylor9870
Helper III
Helper III

DAX measure total not computing my changed value (Has been a pain for me I can't get)

Hi Everyone,

 

Very simplified but could someone explain why this isn't being computed properly? This has been frying my brain for days.😵

 

I need the solution as a measure can't be a calculated column or done in Power Query I need the solution as a measure.

Here are my tables and my measures below.....

 

Table1

IDBingo
A-5
B-20
C-90
D5
E10
F15
G0

 

Total Bingo = SUM('Table'[Bingo])
 
No Negatives = IF('Table'[Total Bingo] < 0,0,'Table'[Total Bingo])
 
End result...
 
Ttaylor9870_0-1673864021491.png

I need all negative values turned into 0's and then the total at the bottom. I would love to do this in power query but my actual reports problem boils down to this same issue and the end result has been built upon measures so the solution in a measure would be extremly helpful.

 

Thanks in advance all you would be a life saver!

 

Many Thanks,

 

Taylor

 

 

 

 

1 ACCEPTED SOLUTION

You can use

No negatives =
SUMX (
    'Nav_item',
    VAR Quantity =
        CALCULATE ( SUM ( 'Nav_item ledger entry'[Quantity] ) )
    VAR OutstandingQuantity =
        CALCULATE ( SUM ( 'Nav_sales line'[Outstanding quantity] ) )
    VAR Difference =
        MAX ( OutstandingQuantity - Quantity, 0 )
    RETURN
        Difference * 'Nav_item'[Selling price]
)

View solution in original post

10 REPLIES 10
Ttaylor9870
Helper III
Helper III

Hi @m-kats @johnt75 ,

 

Would you guys be able to build it with these?

 

Table: Nav_Sales

ID: No

 

Table: Nav_Item

ID: No

 

Table Name: Nav_Item Ledger

ID Name: No

 

Relationships-

Nav_Item Legder -> Nav_Item = Many to One

Nav_Sales -> Nav_Item = Many to One

 

This is such great help thanks guys.
 
Many Thanks,
 
Taylor

 

 

which columns from which tables are involved, and what is the formula ? is it the sum of a column from one table multiplied by the sum of a column from the other table, for the same nav item ?

Hi @johnt75 ,

 

This is it here...

Ttaylor9870_0-1673870135745.png

Ttaylor9870_1-1673871339790.png

 

Relationship has be be like this because this is just a sample from the tables of columns that I've needed.

 

I need to do: Total Outstanding Quantity -  Total Quantity

 

And then assign all negative values from this equation to zeros, then multiply this equation by the Selling price.

 

Here are my Tables...

 

Item NoQuantity
15
210
38
435
56
615
716
817
918
1019

 

No

Selling

Selling Price

Prod Group
15AAA
26BBB
37CCC
48DDD
59EEE

 

 

NoOutstanding QuantityLocation Code
13OOOOOO
24LLLLLLLLLL
35MMMMMM
47PPPPPPPPPP
53SSSSSSSSSSS
68GGGGGGGGGG
79FFFFFFFFFF
83BBBBBBBBB
95NNNNNNNNN
106SSSSSSSSSSS

Many Thanks,

 

Taylor

 

You can use

No negatives =
SUMX (
    'Nav_item',
    VAR Quantity =
        CALCULATE ( SUM ( 'Nav_item ledger entry'[Quantity] ) )
    VAR OutstandingQuantity =
        CALCULATE ( SUM ( 'Nav_sales line'[Outstanding quantity] ) )
    VAR Difference =
        MAX ( OutstandingQuantity - Quantity, 0 )
    RETURN
        Difference * 'Nav_item'[Selling price]
)

Bingo! Thank you very much!

m-kats
Regular Visitor

You shoule also try to build the table inside the measure and then use the SUMX function:

 
No Negatives =
var _table = ADDCOLUMNS( ADDCOLUMNS( SELECTCOLUMNS('TableWithIds', "_Id", 'TableWithIds'[ID]), "_Quantity", SUM(Quantity), "_AvgPrice", AVERAGE(Price)), "Bingo", [_Quantity] * [_AvgPrice])
var _sum = SUMX( FILTER( _table, [Bingo] >=0), [Bingo])
return _sum
m-kats
Regular Visitor

Hello,

you should try 

No Negatives = SUMX(FILTER('Table', 'Table'[Bingo]>=0), 'Table'[Bingo])
and the result is:
mkats_0-1673864809826.png

Hope I helped!!

 
 
johnt75
Super User
Super User

You can use

No negatives =
SUMX ( 'Table', IF ( 'Table'[Total Bingo] < 0, 0, 'Table'[Total Bingo] ) )

Hi @johnt75 @m-kats ,

 

Is there a way you can do this without having to specify the table name? I have built a couple measure stacking ontop of eachother and some measures aren't in the same table as others. E.g. I have multiplied Quantity * Average price to get value but both column's sit in different tables.

Many Thanks

If the tables have a relationship then you could use RELATED, e.g.

My measure =
SUMX ( 'Many side', 'Many side'[column] * RELATED ( 'One side'[column] ) )

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors
Top Kudoed Authors