The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Good Morning,
I am attempting to write a DAX Command to create new columns for Sales from a specific year. I am attempting to compare YOY data from today back to 1998 on a line or bar graph with the Y axis being Sales $ and the X Axis being the month. I would also like to be able to filter those columns by Customer. Currently I have the following expression and it is not working correctly:
Solved! Go to Solution.
😐 Oops...that's what I get for doing this in Notepad.
This instead
2021 Sales =
CALCULATE(
[Total Sales],
FILTER(
ALLEXCEPT(
SALES,
CustomerID
),
SALES[InvoiceDate].[Year]= 2021
),
FILTER(
'Customer',
'Customer'[CustomerID] = SELECTEDVALUE('Customer'[CustomerID])
)
)
It's returning the same number for all Customers because you used ALL() in the FILTER function.
Try this...
2021 Sales =
CALCULATE(
[Total Sales],
FILTER(
ALLEXCEPT(
SALES,
CustomerID
),
SALES[InvoiceDate].[Year]= 2021
),
'Customer'[CustomerID] = SELECTEDVALUE('Customer'[CustomerID])
)
assumes you have a field named CustomerID
Unfortunately, that is returning the following error :
A function 'SELECTEDVALUE' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
😐 Oops...that's what I get for doing this in Notepad.
This instead
2021 Sales =
CALCULATE(
[Total Sales],
FILTER(
ALLEXCEPT(
SALES,
CustomerID
),
SALES[InvoiceDate].[Year]= 2021
),
FILTER(
'Customer',
'Customer'[CustomerID] = SELECTEDVALUE('Customer'[CustomerID])
)
)
Thank You! That worked perfect.
You're welcome. Glad I could help! 🙂
User | Count |
---|---|
16 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
12 | |
8 | |
8 |