Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hi,
I am new to PowerBI. I am trying to create a calculated measure based on the condition. For Example, I am trying to create measure for the following condition
SalesAverage= ((SUM(Total Sales $) Where AccountCode=410000) / (Sum(Total Sales Quantity) where AccountCode=420000))
Please help me to get this done.
Thanks.
Solved! Go to Solution.
@jaymanivannan response is great. To add to this, rather than using the / symbol and have to make a divide by zero check, just use the Divide() function. I've also set this out using a spacing format, which is a good habit to get yourself into.
Here is an update
SalesAverage = DIVIDE( CALCULATE( SUM(Total Sales $), [AccountCode]=410000 ), CALCULATE ( Sum(Total Sales Quantity), [AccountCode]=420000 ) )
Hello!
How do you write this code in DAX?
Select column1
from table1
Where column3>column2;
(Consider column1 as text field and column 2 and 3 as value field).
Hi,
You should use the CALCULATE function.
Your formula should look something like this:
SalesAverage:= CALCULATE (SUM(Total Sales $), [AccountCode]=410000) / CALCULATE (Sum(Total Sales Quantity), [AccountCode]=420000).
I would also add division by zero condition check
Michael
@jaymanivannan response is great. To add to this, rather than using the / symbol and have to make a divide by zero check, just use the Divide() function. I've also set this out using a spacing format, which is a good habit to get yourself into.
Here is an update
SalesAverage = DIVIDE( CALCULATE( SUM(Total Sales $), [AccountCode]=410000 ), CALCULATE ( Sum(Total Sales Quantity), [AccountCode]=420000 ) )
@Anonymous@AnonymousWhat if i want to apply where condition on categorical variable, say account status= Yes or No, want to calculate for those accounts whose status is No. Pls advise.
It's similar, depends on a datatype of your categorical variable.
If it's string then just use smth like: CALCULATE(SUM([Amount]),Account_Status="No")
or this:
CALCULATE(SUM(Fact_Table[Amount]),Filter(Accounts,Accounts[Account_Status]="No"))
in case you have two connected tables
Michael
Does anyone know how to refer to a record the user is interacting with rather than a static value?
Example:
- Table visualization that acts as a slicer
- User clicks a record in the table
- Card visualization with a Measure set to:
measure =
CALCULATE(
SUM(Fact_Table[Amount]),
Filter(Accounts,Accounts[Account_Status]=SELECTED.ACCOUNT_STATUS)
)
Where "SELECTED.ACCOUNT_STATUS" is the ACCOUNT_STATUS column in the Table visualization.
- I dont' want to create a measure for every single value of a given column.
- If there were 15 statuses, would I need 15 measures or is there a way to dynamically filter based on user selection?
Thank you
@ericOnline I believe you would need to use https://docs.microsoft.com/en-us/dax/username-function-dax and then find some way of relating that information to your account information. If the email address is shared, then you might have some luck.
Thanks for the reply @Anonymous , but I'm not sure how that function would help. I'm attempting to grab a column from a Table vis that the user has selected. Then use that column as a variable for a measure.
Ok i definately misunderstood. I dont believe there is a dax can interact with visual selections so directly. You might need to use indirect methods such as HASONEFILTER.
@Anonymous, This is working !!!. Thanks for the quick response. No Zero divide error. Thank you once again.
I want to thank @Anonymous too. He did a lot of the work.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
86 | |
80 | |
53 | |
39 | |
39 |
User | Count |
---|---|
104 | |
85 | |
47 | |
44 | |
43 |