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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Kosta88
New Member

Convert DAX to M (Variables, conditions, Filter, in, countrows)

New=
VAR NewPostcode =[Postcode]
VAR testCreated =[created date]
VAR testEnd = [Completion Date]
VAR MidLevel =[Mid_Level_Work]
RETURN

COUNTROWS(
FILTER(source, MidLevel IN {"one","two", "three"} && [Postcode] = NewPostcode && created date] >= testCreated && [Completion Date] <= testEnd ))
5 REPLIES 5
Nathaniel_C
Super User
Super User

Hi @ImkeF , @KenPuls 

How would you solve this?

Thank you,

Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




v-yangliu-msft
Community Support
Community Support

Hi  @Kosta88 ,

You can first use the if function to determine whether [MidLevel] contains {one,two,three} and [Postcode]=current [Postcode], etc.

if List.Contains({"one","two", "three"},[MidLevel])
then 1
else 0

In grouping to accumulate counts based on conditions:

Grouped Running Totals in Power Query • My Online Training Hub

Solved: Cumulative sum in Power query editor - Microsoft Power BI Community

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Nathaniel_C
Super User
Super User

Hi @Kosta88 ,

Use one of the filters in the conditional column (I used 2) to see the syntax, then add the rest of the conditions to the formula bar. You will have to use "and" and "or". Note that the key words are all lower case, and you have to write out "then" and "else."

 

Finally you will need to filter the table based on your new column.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 

 

Nathaniel_C_0-1656947876117.pngNathaniel_C_1-1656947969005.png

 

Nathaniel_C_2-1656948333271.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Super User
Super User

Hi @Kosta88 
Where do your variables come from? Are they measures or columns? If they are measures this will not work.  If they are column headings, then this would be a conditional column in Power Query - it will allow you to do the multiple conditions.  Find this under Add Column tab.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi Nathaniel, thank you for the promt reply.

 

 

My variables are columns headings as you mentioned.

 

I have tried to go under transform data, addcolumn , custom column but I am not sure how to convert the DAX code to Power query syntax.

 

Could you please provide a sample code that could help me please.

 

Thank you again.

 

Kosta

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors