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

DAX Help - Define Variable Using Two Tables

Community,

I currently have three tables. I would like to use two of the tables to define a variable, then apply the variable along with values in the third table to calculate a value.

Below are the tables and what I would like to achieve, but getting the DAX correct has been a bit of a struggle, any help would be much appreciated. (Also in the example included, I would not have the option to merge any of the tables)

 

Create a Measure, CL_ATD1

  • Where CL_ATD1 = ((Slope[CL_x^2]*V)-(Slope[CL_x]*V))+(Slope[CL_icpt])
  • What is V?
    • V is the value where PassID[Pass ID] and ATD[Pass ID] match, then the column in PassID that has the value 100, retrieves the matching columns value from the ATD table where ATD[Attitude ID] = “1”
    • In this example V = 1.5
  • In this example the measure CL_ATD1 =
    • ((0.00232795*1.5^2)-(0.000113306*1.5))+(-0.846558)
    • = -0.84149

PolyTables.PNG

 

 

 
 
 
1 ACCEPTED SOLUTION
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please unpivot table ATD and table PassID first:

Table ATD:                                                         Table PassID:

6.PNG   7.PNG

Then try this measure:

Measure = 
var SameID = CALCULATE(MAX(ATD[Pass ID]),FILTER(ATD,ATD[Attitude ID]=ATD[Pass ID]))
var Attribute = CALCULATE(MAX(PassID[Attribute]),FILTER(PassID,PassID[Pass ID]=SameID&&PassID[Value]=100))
var variable = CALCULATE(MAX(ATD[Value]),FILTER(ATD,ATD[Attitude ID]=ATD[Pass ID]&&ATD[Attribute]=Attribute))
return
MAX(Slope[CL_x^2])*variable*variable-MAX(Slope[CL_x])*variable+MAX(Slope[CL_icpt])

Choose a card visual, the result shows:

5.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto Zhi

View solution in original post

3 REPLIES 3
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please unpivot table ATD and table PassID first:

Table ATD:                                                         Table PassID:

6.PNG   7.PNG

Then try this measure:

Measure = 
var SameID = CALCULATE(MAX(ATD[Pass ID]),FILTER(ATD,ATD[Attitude ID]=ATD[Pass ID]))
var Attribute = CALCULATE(MAX(PassID[Attribute]),FILTER(PassID,PassID[Pass ID]=SameID&&PassID[Value]=100))
var variable = CALCULATE(MAX(ATD[Value]),FILTER(ATD,ATD[Attitude ID]=ATD[Pass ID]&&ATD[Attribute]=Attribute))
return
MAX(Slope[CL_x^2])*variable*variable-MAX(Slope[CL_x])*variable+MAX(Slope[CL_icpt])

Choose a card visual, the result shows:

5.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto Zhi

Anonymous
Not applicable

@v-gizhi-msft ,

Do you have any thoughts on how to modify the DAX to solve for each of the different "Attitude ID"? The current DAX only solves for one of the "Attitude ID".

I would like to end up with a table that looks something like this (CL_ATD1 is your measure in the original post), but with the correct calculated values. (In this example the variables need to muptiple with would be 1.5, 0, -1.5, -2.5, -3.5)

ATDAll.PNG

I have tried introducing some HASONEVALUE in to the DAX but no luck in getting the correct values yet. Any help with this would be much appreciated. Also if you like I can make this a new post.

 

Thanks!

Anonymous
Not applicable

@v-gizhi-msft ,

Thanks so much for the help!!

Your DAX works perfect.

 
 
 
 
 
 

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.