Forum Discussion
Does Excel 2016 Pro Dax does not accept Variable Only HardCode? It is giving me Error
CALCULATE(
[Tt Votes],
fVotesAmioun2016[CandidateEN] in VALUES( CandidateCompared ) ,
fVotesAmioun2016[Region]="Sharqi"
)Your suggestion does not work.
- Anonymous1 year agoNot applicable
Hi DSR,
Thanks for reaching out to the Microsoft fabric community forum.
It looks like you are trying to create a dynamic DAX measure that filters votes by region and a candidate name, where the candidate name is coming from an Excel cell. You're also using Power Pivot in Excel 2016. The logic of your measure (CALCULATE([Tt Votes], fVotesAmioun2016[CandidateEN]="John", fVotesAmioun2016[Region]="Sharqi")) is fine, the issue lies in how you're trying to pass the candidate name dynamically.
The variable CandidateCompared you've created in Power Query returns a scalar value, just a single piece of text, like "John". DAX inside a measure doesn't accept that kind of external scalar reference directly. In Excel 2016 specifically, Power Pivot doesn't support passing variables from Power Query into DAX expressions in this way.
You can use a disconnected table and SELECTEDVALUE. First create a small table in Excel (e.g., CandidateCompared_Criteria) with a single column listing candidate names then load it into the Data Model. Do not create a relationship between this table and others. Now add a slicer in your Excel sheet based on this table so you can select a candidate. Then try the this DAX measure "SelectedCandidate := SELECTEDVALUE(CandidateCompared_Criteria[CandidateCompared_Criteria])".
Also rewrite your main measure:
Study Candidate Votes in Sharqi :=
CALCULATE(
[Tt Votes],
fVotesAmioun2016[CandidateEN] = [SelectedCandidate],
fVotesAmioun2016[Region] = "Sharqi"
)This approach works because DAX can evaluate [SelectedCandidate] as a valid scalar during measure evaluation.
I would also take a moment to thank Deku, for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Best Regards,
Hammad.
Community Support TeamIf this post helps then please mark it as a solution, so that other members find it more quickly.
Thank you.
- Anonymous1 year agoNot applicable
Hi DSR,
As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help.
If yes, you are welcome to share your workaround and mark it as a solution so that other users can benefit as well. If you find a reply particularly helpful to you, you can also mark it as a solution.
If you still have any questions or need more support, please feel free to let us know. We are more than happy to continue to help you.
Thank you for your patience and look forward to hearing from you.- Anonymous1 year agoNot applicable
Hi DSR,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution so that other community members can find it easily.
Thank you.