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

Please help me convert DAX to Power Query

Hello All,

I am trying to convert the below DAX (Calculated column) function to a power query 

QEnd = IF(RIGHT('Table'[Quarter],2) = "Q1", Date(left('Table'[Quarter],4),03,31),

IF(RIGHT('Table'[Quarter],2) = "Q2", Date(left('Table'[Quarter],4),06,30),

IF(RIGHT('Table'[Quarter],2) = "Q3", Date(left('Table'[Quarter],4),09,30),

IF(RIGHT('Table'[Quarter],2) = "Q4", Date(left('Table'[Quarter],4),12,31)))))

 

I am trying to achieve the second column in the image using power query 

 

 

q.png

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

Try this:

1) Go to Add Column tab and select Custom Column.

2) In code window, paste this:

 

if Text.End([Quarter], 2) = "Q1" then #date(Number.From(Text.Start([Quarter], 4)), 03, 31)
else if Text.End([Quarter], 2) = "Q2" then #date(Number.From(Text.Start([Quarter], 4)), 06, 30)
else if Text.End([Quarter], 2) = "Q3" then #date(Number.From(Text.Start([Quarter], 4)), 09, 30)
else if Text.End([Quarter], 2) = "Q4" then #date(Number.From(Text.Start([Quarter], 4)), 12, 31)
else null

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

4 REPLIES 4
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

Try this:

1) Go to Add Column tab and select Custom Column.

2) In code window, paste this:

 

if Text.End([Quarter], 2) = "Q1" then #date(Number.From(Text.Start([Quarter], 4)), 03, 31)
else if Text.End([Quarter], 2) = "Q2" then #date(Number.From(Text.Start([Quarter], 4)), 06, 30)
else if Text.End([Quarter], 2) = "Q3" then #date(Number.From(Text.Start([Quarter], 4)), 09, 30)
else if Text.End([Quarter], 2) = "Q4" then #date(Number.From(Text.Start([Quarter], 4)), 12, 31)
else null

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

Thank you for helping, I tried this there are no syntax errors although I do not get the desired results, am I missing something?

1.PNG

 

2.PNG 

@Anonymous ,

 

Sorry, I updated the code staright after I posted it with a correction.

Refresh your browser on this page then use the updated code please.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

Thank you so much for helping this intern 🙂 

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.

Top Solution Authors
Top Kudoed Authors