Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
TommySidds
Frequent Visitor

LookupValue with variable to set column reference

I have a query pulling a bunch of thermocouple data from some oven equipment per part we will call this table CAC_AllData. A second query that is pulling the what thermocouples were used for that part table is call CAC_Attach. 

The issue i am having is that the CAC_Alldata table creates columns for all 260 thermocouples, but the part only uses 10, and the 10 used could be different every time. So because of this I created the SNAttach query to determine which TCs were used on the part.

What i am trying to do is create a new table with DataID number Serial number and the 10 thermocouples used. 

 

I can determine which TC was used by using a lookup formula

TC2 =
LOOKUPVALUE(CAC_ATTACH[AttachmentName],CAC_ATTACH[SerialNumber],[SerialNumber],CAC_ATTACH[Rank Attachment],3)
This will give me any range between TC1 - TC260 
 
What I am trying to do is set that lookupvalue formula so the the reult table is set up as Variable using a formula. 
TC2 =
VAR TC =
"CAC_AllData["&LOOKUPVALUE(CAC_ATTACH[AttachmentName],CAC_ATTACH[SerialNumber],[SerialNumber],CAC_ATTACH[Rank Attachment],3)&"]"         ------ This would create the Table and Column Name
Result
LOOKUPVALUE(TC, CAC_AllData[SerialNumber],[SerialNumber], CAC_AllData[DataPointID],[Datapointid])
 
 so my final table would look something like this
TommySidds_0-1746035958622.png

 

 
Is this even possible. Or am i going about it a wrong way.
 
1 ACCEPTED SOLUTION
v-kathullac
Community Support
Community Support

Hi ,

can you try with below debug steps to solve your issue.

  • Load your raw data table CAC_AllData into Power BI In Power Query, select all columns from PTC1 to PTC260.
  • Right-click and choose Unpivot Columns Rename the resulting columns:
  • Attribute → AttachmentName
  • Value → PTC_Value
  • You will now have a table with columns: SerialNumber, AttachmentName, PTC_Value
  • Load or create a separate table called UsedAttachments with columns: SerialNumber, AttachmentName, Rank
  • In Power BI model view, create relationships:
  • Between CAC_Unpivoted[SerialNumber] and UsedAttachments[SerialNumber]
  • Between CAC_Unpivoted[AttachmentName] and UsedAttachments[AttachmentName]
  • Optionally, instead of 2 relationships, create a calculated column in both tables:
  • Serial_Attach_Key = SerialNumber & "-" & AttachmentName
  • Create a relationship on Serial_Attach_Key between the two tables

Create a calculated column in the unpivoted table:

IsUsed =
CALCULATE(
COUNTROWS(UsedAttachments),
FILTER(
UsedAttachments,
UsedAttachments[SerialNumber] = CAC_Unpivoted[SerialNumber] &&
UsedAttachments[AttachmentName] = CAC_Unpivoted[AttachmentName]
)
) > 0
Use this column to filter your visuals to show only rows where IsUsed = TRUE

Alternatively, create a calculated table with only matching rows:


FilteredPTCData =
FILTER (
CAC_Unpivoted,
CALCULATE (
COUNTROWS (UsedAttachments),
UsedAttachments[SerialNumber] = CAC_Unpivoted[SerialNumber],
UsedAttachments[AttachmentName] = CAC_Unpivoted[AttachmentName]
) > 0
)

 

If it is solved, please mark the helpful reply or share your solution and Accept it as solution, it will be helpful for other members of the community who have similar problems as yours to solve it faster.


Regards,

Chaithanya.

View solution in original post

5 REPLIES 5
v-kathullac
Community Support
Community Support

Hi @TommySidds  ,

we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

Regards,

Chaithanya.

v-kathullac
Community Support
Community Support

Hi @TommySidds  ,

we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

Regards,

Chaithanya.

v-kathullac
Community Support
Community Support

Hi ,

can you try with below debug steps to solve your issue.

  • Load your raw data table CAC_AllData into Power BI In Power Query, select all columns from PTC1 to PTC260.
  • Right-click and choose Unpivot Columns Rename the resulting columns:
  • Attribute → AttachmentName
  • Value → PTC_Value
  • You will now have a table with columns: SerialNumber, AttachmentName, PTC_Value
  • Load or create a separate table called UsedAttachments with columns: SerialNumber, AttachmentName, Rank
  • In Power BI model view, create relationships:
  • Between CAC_Unpivoted[SerialNumber] and UsedAttachments[SerialNumber]
  • Between CAC_Unpivoted[AttachmentName] and UsedAttachments[AttachmentName]
  • Optionally, instead of 2 relationships, create a calculated column in both tables:
  • Serial_Attach_Key = SerialNumber & "-" & AttachmentName
  • Create a relationship on Serial_Attach_Key between the two tables

Create a calculated column in the unpivoted table:

IsUsed =
CALCULATE(
COUNTROWS(UsedAttachments),
FILTER(
UsedAttachments,
UsedAttachments[SerialNumber] = CAC_Unpivoted[SerialNumber] &&
UsedAttachments[AttachmentName] = CAC_Unpivoted[AttachmentName]
)
) > 0
Use this column to filter your visuals to show only rows where IsUsed = TRUE

Alternatively, create a calculated table with only matching rows:


FilteredPTCData =
FILTER (
CAC_Unpivoted,
CALCULATE (
COUNTROWS (UsedAttachments),
UsedAttachments[SerialNumber] = CAC_Unpivoted[SerialNumber],
UsedAttachments[AttachmentName] = CAC_Unpivoted[AttachmentName]
) > 0
)

 

If it is solved, please mark the helpful reply or share your solution and Accept it as solution, it will be helpful for other members of the community who have similar problems as yours to solve it faster.


Regards,

Chaithanya.

Sahir_Maharaj
Super User
Super User

Hello @TommySidds,

 

If you're building a summary table, you can pivot it back using this DAX. Could you please try this approach:

ResultTable =
VAR Base =
    SELECTCOLUMNS (
        FILTER (
            Unpivoted_CAC_AllData,
            Unpivoted_CAC_AllData[ThermocoupleName] IN 
                SELECTCOLUMNS (
                    FILTER (
                        CAC_ATTACH,
                        CAC_ATTACH[SerialNumber] = Unpivoted_CAC_AllData[SerialNumber]
                    ),
                    "TC", CAC_ATTACH[AttachmentName]
                )
        ),
        "DataPointID", [DataPointID],
        "SerialNumber", [SerialNumber],
        "Thermocouple", [ThermocoupleName],
        "Value", [Value]
    )
RETURN
    SUMMARIZECOLUMNS (
        Base[DataPointID],
        Base[SerialNumber],
        "TC1", CALCULATE(MAX(Base[Value]), Base[Thermocouple] = "TC1"),
        "TC2", CALCULATE(MAX(Base[Value]), Base[Thermocouple] = "TC2"),
        ...
        "TC10", CALCULATE(MAX(Base[Value]), Base[Thermocouple] = "TC10")
    )

 


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

 I couldnt get it to work, I am also still learning PowerBI and DAX.

Here is a portion of the raw data CAC_AllData (Note this table will have over 260 PTCXXX items and i can use any 10 PTCs at any time)

 

 

SerialNumberPTC1PTC10PTC100PTC101PTC102PTC103PTC104PTC105PTC106PTC107PTC108PTC109PTC11PTC110PTC111PTC112
SN0001000072.3000030572.87271.90000272.40000200000073.5
SN0001000072.3000030572.87271.90000272.40000200000073.5
SN0001000072.4000015372.972.171.90000272.40000200000073.5
SN0001000072.4000015372.872.171.90000272.500000073.5
SN0001000072.3000030572.972.17272.500000073.599998
SN0001000072.4000015372.872.17272.500000073.699997
SN0001000072.572.872.172.09999872.59999800000073.800003
SN0001000072.599998477372.372.19999772.80000300000073.900002
SN0001000072.8000030573.272.572.30000372.90000200000074.199997
SN0001000073.0999984773.472.772.573.19999700000074.400002
SN0001000073.3000030573.67372.69999773.40000200000074.800003
SN0001000073.5999984773.873.27373.69999700000075.099998
SN0001000073.9000015373.973.573.19999773.90000200000075.400002
SN0001000074.1999969574.273.873.574.30000300000075.800003
SN0001000074.5999984774.674.373.90000274.80000300000076.400002
SN0001000075.1999969575.174.974.40000275.40000200000077
SN0001000075.9000015375.675.474.90000275.90000200000077.900002
SN0001000076.5999984776.476.275.59999876.69999700000078.699997

 

 

Here is a query that tell me what attachments were used for that spefic serial number. I also created a rank formula to rank the TCs used. That way i could use that to look up TC 1, TC 2.....

SerialNumberAttachmentNameRank
SN0001PTC1021
SN0001PTC1032
SN0001PTC1043
SN0001PTC1054
SN0001PTC1065
SN0001PTC1126
SN0001PTC1137
SN0001PTC1148
SN0001PTC1169
SN0001PTC11810

 

I want to be able to create a table that only pulls the data from the TCs that were used. In excel i can do a lookup that will use the TC name in the attach table and set that as my lookup column. I just cant figure out how to do that with DAX/PowerBI. Maybe there is even a better way to do this.

 

  PTC102PTC103PTC104PTC105PTC106
DataPointIDSerial NumberTC1TC2TC3TC4TC5
334638SN000172.372.872.071.972.4
334639SN000172.372.872.071.972.4
334640SN000172.472.972.171.972.4
334641SN000172.472.872.171.972.5
334642SN000172.372.972.172.072.5
334643SN000172.472.872.172.072.5
334644SN000172.572.872.172.172.6
334645SN000172.673.072.372.272.8
334646SN000172.873.272.572.372.9
334647SN000173.173.472.772.573.2
334648SN000173.373.673.072.773.4
334649SN000173.673.873.273.073.7
334650SN000173.973.973.573.273.9
334651SN000174.274.273.873.574.3
334652SN000174.674.674.373.974.8
334653SN000175.275.174.974.475.4

hopefully this helps.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.