Explanation :
FILTER ( VALUES ( Products[Brand] ), Products[Brand] = “Contoso” ) this statement will ensure that a table of only only one value is returned i.e contoso.
Caclulatetable and keepfilter will ensure that the filter stays on Contoso when the values(Products[Brand]) is traversed.
Good one – I always enjoy these challenges from you. I was hoping to find a way to annoy you by using a simple COALESCE based solution instead of an IF statement to get you back for Rickrolling me earlier this week. But you smartly tightened the hatches in your rules and I couldn’t get it to work.
Note: I had originally written this using FILTER instead of the CALCULATETABLE function, but the solution only works with the latter.
This works because the way you had originally written Contoso Sales overrode the filter context from brand, but KEEPFILTERS restores that context subject to the condition in the KEEPFILTERS statement.
If you put that code into Power BI, you’ll find that’s not a valid measure. Two major tips for you as you learn DAX:
Learn how to format your DAX code by indenting - this will be enormously helpful in identifying error, missing parameters, missing parentheses, etc. There are also a number of helpful tools to do this automatically, but when you’re first learning I think developing the habit of manually formatting as you write your DAX code is incredibly valuable.
For any DAX function you use, make sure you understand what the function returns (table or scalar) and what the form of the inputs is. DAX.guide is extremely helpful for this. As you can see from the DAX.guide entry, COUNTX returns a scalar, the first input is a table (can be a physical table like Products, or a virtual table created by table functions like ADDCOLUMNS, SUMMARIZE, DISTINCT, VALUES, etc.), the second input is an “expression” which means it can be a column reference (physical or virtual), a measure or a variable.
I absolutely applaud you jumping in and giving this a go, but one thing you should know is that @AntrikshSharma 's DAX challenges are usually quite advanced and deal with concepts and/or functions that as a beginner you will not have had much exposure to yet.
Thank you so much for your support and guidance. I understood how much it is important to understand DAX concepts well…Thank you for advising me on how to proceed for upgrading my skills.
I am confident that with all your vast knowledge and expertise in this field, I shall learn a lot. I will start following as per your above guidance.
This text will be blurred[/spoiler] Introduce a friendly and helpful DAX modifIer to create an intersection of the values and maintain the current filter context.
Thank you for sharing your experiences around Power BI, please don’t hesitate to add more discussion or add value to wherever you think you possess the experience or knowledge that can help others.
We are closing this thread due to inactivity.
We appreciate the initiative and your help in this group!