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
Anonymous
Not applicable

Expression for comparing a column vs measure for each row in a table

Hi All,

 

I am a beginner in DAX and I am trying to figure out how to achieve the following using either a calculated column or a measure.

Requirement:

Find the 

"No of Products" ( condition : No of days a product is on hand based on Avg usage in Selected Month Range > Avg of days in the Selected Month Range)
Dimension Table has all Products attributes and On Hand Quantity 
Fact Table has Month and Usage 
Dynamic filter for selecting month Range.
 
Steps done: 
Measure1= Calculated the Quantity used based on Month Range selected 
Measure2 = Calculated No of days based on the Month range selected
Measure3 = Calculated Avg no of days based on the Month range selected
Calculated Column1: (Here I am trying to create a flag) in Dimension table
SWITCH (
TRUE (),
AND(Dimension [Quantity_On_Hand]>0, Measure1>0), Dimension[Quantity_On_Hand]/Measure1/Measure2,
AND(Dimension[Quantity_On_Hand]>0,Measure1<=0), -99,
    Dimension[Quantity_On_Hand]=0, 0
)
Measure4 =
CALCULATE (
DISTINCTCOUNT(Product_No),
FILTER(Dimension,Calculated Column1 > Measure3),
Dimenson [Product_Status]="A")
 
Though I am getting Approx value but it doesnt seem dynamic as when I change the month range the Measure4 doesnt change.
 
I would appreciate any help on this.
 
Thanks.
3 REPLIES 3
Stachu
Community Champion
Community Champion

the calculated column in a table is not dynamic - it is populated only when the table is refreshed. So Measure4 is always filtering the same A records

you could create a temporary one using ADDCOLUMNS in your Measure4

 

I could help you write it if you post some example (in format that can be copied to PowerBI) from your model with anonymised data? Like this (just copy and paste into the post window).

Column1Column2
A1
B2.5

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Hi Stachu,

Did you get a chance to look into the sample data?

Thanks


@Stachu wrote:

the calculated column in a table is not dynamic - it is populated only when the table is refreshed. So Measure4 is always filtering the same A records

you could create a temporary one using ADDCOLUMNS in your Measure4

 

I could help you write it if you post some example (in format that can be copied to PowerBI) from your model with anonymised data? Like this (just copy and paste into the post window).

Column1Column2
A1
B2.5

 


 

Anonymous
Not applicable

Dimension:

Product   
Product noProduct nameQuantity On handID
Ar45Gloves113.51
Tu78Cap26.72
Fu07Hat250003
Bx12Coats04
Wv89Socks300.45
Re65Shirts100.66

 

Fact:

Usage  
IDMonth First DateQuantity Used
101/01/191.5
102/01/190.2
103/01/195.6
102/01/191.2
203/01/190.9
202/01/190.02
201/01/192.2
205/01/190
203/01/193.6
305/01/190.005
302/01/190.06
304/01/193.4
307/01/195.2
303/01/191.2
406/01/199.8
402/01/195.7
504/01/190.06
606/01/192.6
605/01/19-1.9
603/01/19-2.5

 

Month range Selected  Measure 2Measure 3
01/01/2019 to 05/01/2019Jan 2019 to May 2019 15030

 

Output    
     
Product noProduct nameQuantity On handMeasure 1Calculated Column 1
Ar45Gloves113.58.50.09
Tu78Cap26.76.720.03
Fu07Hat250004.6735.69
Bx12Coats05.70
Wv89Socks300.40.0633.38
Re65Shirts100.6-4.4-99

 

# Of Products
2

 

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.

Top Solution Authors