Calculate Sum in DAX - filter

Both the columns are in the same table. I've been trying with CALCULATE(SUM)
but how do I apply the OR condition?

Have you tried using CALCULATE?
I've assumed your table is called Table1.
DAX works differently from Excel formulas. The filtering needs to happen outside SUM with calculate.
Calculation =
CALCULATE (
SUM ( 'Table1'[CC_BASE_AMOUNT] ),
FILTER (
ALL ( 'Table1'[CC_ACCOUNT] ),
[CC_ACCOUNT] IN { "10110101", "10110201", "10110303", "10119701", "10119901" }
)
)

Related

In DAX, is it possible to check if value exists in another table using measure instead of calculated column?

I'm hoping to create a measure of distinct count of a customer column, on the condition if customers in this column does not exist in another table's customer column.
I know I can create a calculated column checking if the customer exists, and then use the calculate function filtering out those who do exist. But is it possible to achieve this without creating the calculated column?
Please note this is in Power Pivot, not Power BI so I can't really use 'treatas' or 'in'. Thanks a lot.
Assuming tables named Table1 and Table2:
MyMeasure :=
VAR T2Customer =
VALUES( Table2[Customer] )
RETURN
CALCULATE(
DISTINCTCOUNT( Table1[Customer] ),
NOT (
CONTAINSROW(
T2Customer,
Table1[Customer]
)
)
)
Yes, You can achieve it using EXCEPT()function:
Let's say that we have 2 tables like this:
Customer_Table1:
Customer_Table2:
Now we can use this measure to achieve our result:
CountOfDistinctCusts =
COUNTROWS (
EXCEPT (
VALUES ( Customer_Table1[Customer] ),
VALUES ( Customer_Table2[Customer] )
)
)
If we test the code:

Retrieving a maximum value from a SUMMARIZECOLUMNS table

I have a query and the following results, executed from DAX Studio:
What I would like to do now is to expand the query so that I can retrieve maximum Total Sales from the table that SUMMARIZECOLUMNS produces. For example, based on the rows displayed in the results, I'd like a way to return 10234.35. Is there a way to do this?
Wrap the whole SUMMARIZECOLUMNS part in a MAXX.
MAXX(
SUMMARIZECOLUMNS([...]),
[Total Sales]
)
The MAXX(<table>,<expression>) function iterates through each row of the <table> from its first argument taking the maximum value of the <expression> in the second argument.
As #greggyb points out, a more efficient implementation would be
CALCULATE (
MAXX ( VALUES ( Customers[Customer Key] ), [Sales Amount] ),
FILTER ( Products, Products[Product Name] = "Fabrikam Laptop12v M2080 Silver" ),
FILTER ( 'Calendar', 'Calendar'[Calendary Year] = 2008 )
)
since this doesn't require creating the whole summary table in memory.

How to combine 6 tables in one Matrix, show top 12 and categorize the rest as others?

I need to be able to sum availability based on product and say show me top 3, and categorize the rest as Others. I have two tables in a matrix connected by a product table.
I tried so many ways -
i was able to create this measure for July (which is what i will be sorting with) - I get the correct ranking column for July.
i know i'm missing something. i tried to take that ranking measure statement and add an if statement and couldn't get it to do the ranking.
the picture would make more sense *(my formulas are based on actual column names)
Partner Ranking =
VAR summry =
SUMMARIZE (
ALLSELECTED ( Latest ),
[partner_group],
"Sum", COUNT ( Latest[site_url] )
)
VAR tmp =
ADDCOLUMNS ( summry, "RNK", RANKX ( summry, [Sum],, DESC, DENSE ) )
RETURN
MAXX (
FILTER ( tmp, [partner_group] = SELECTEDVALUE ( Latest[partner_group] ) ),
[RNK]
)
I don't know what to do next. how can i do this when i have a separate table that is the product name that links the two tables?

How to calculate a measure based on a decreasing/increasing column's value in DAX

I have a Sales table and related dimension tables. MySales table contains columns : Week, StoreID, SalesSeasonID, ProductKey and metrics. My dimensions are related to sales table (Date,SalesSeason,Store,Product tables).
I need to find Sales Quantity (LastYear and LastSeason), as a measure
You can find a sample below:
My purpose is when user selected SaleseasonID[4] then it will return 2 as SalesQuantity.
How can I calculate this measure by DAX formula?
Try:
PYSales =
SUMX (
VALUES ( Table1[YearWeek] ),
CALCULATE (
SUM ( Table1[SalesQuantity] ),
ALL ( Table1[SalesSeasonID] ),
FILTER (
ALL ( Table1[YearWeek] ),
Table1[YearWeek] = EARLIER ( Table1[YearWeek] ) - 100
)
)
)
Worked example PBIX file, using your sample data: https://pwrbi.com/so_55703551/

DAX - Lookup value to retrieve exchange rate

In table "Paypal", I have:
And in table "Câmbios":
And now, I'm adding a calculated column to "Paypal" table with the formula:
Câmbio = LOOKUPVALUE('Câmbios'[Câmbio];'Câmbios'[Mês];MONTH('Paypal'[Date]))
Which is returning the error:
A table of multiple values was supplied where a single value was expected.
This doesn't make sense to me.
Can anyone help?
Thanks
The problem is Câmbios table contains repeated values for at least one month and the LOOKUPVALUE function doesn't know which value use to retrieve the specified column.
You can use instead:
Cambio =
CALCULATE (
MAX ( Cambio[Cambio] ),
FILTER ( Cambio, [Mes] = MONTH ( EARLIER ( Paypal[Date] ) ) )
)
Or delete the repeated values from Cambios[Mes].

Resources