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
HamidBee
Impactful Individual
Impactful Individual

How do I complete this DAX equation so that it returns the desired text?

I am working with the following DAX equation. I'd like it to return either "Petrol" or "Diesel" but I'm not sure how to complete the DAX equation after I type 'return'. 

Petrol or Diesel = VAR Y = ADDCOLUMNS('Parking Data',"Petrol or Diesel", IF(('Parking Data'[Parking Amount])=[Petrol Price (£)],"Petrol","Diesel"))

RETURN Y

 

Does anyone have any suggestions?

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @HamidBee .

 

Maybe like this?

Petrol or Diesel = VAR Y = ADDCOLUMNS('Parking Data',"Petrol or Diesel", IF(('Parking Data'[Parking Amount])=[Petrol Price (£)],"Petrol","Diesel"))

RETURN 
MAXX ( Y, [Petrol or Diesel])

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

6 REPLIES 6
tackytechtom
Super User
Super User

Hi @HamidBee .

 

Maybe like this?

Petrol or Diesel = VAR Y = ADDCOLUMNS('Parking Data',"Petrol or Diesel", IF(('Parking Data'[Parking Amount])=[Petrol Price (£)],"Petrol","Diesel"))

RETURN 
MAXX ( Y, [Petrol or Diesel])

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Nice, it worked. I like that 'outside of the box' thinking. I've never actually used the MAXX function before. 

tackytechtom
Super User
Super User

Hi @HamidBee,

 

Would you like to add a new column to an existing table? 


If yes, I would just create a calculated column with this:

CalculatedColumn =
IF(('Parking Data'[Parking Amount])=[Petrol Price (£)],"Petrol","Diesel"))

 

Does this solve your issue? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

The problem with using that equation is that it gives me the following error:

error3.png


The syntax for ')' is incorrect. (DAX(IF(('Parking Data'[Parking Amount])=[Petrol Price (£)],"Petrol","Diesel")))).

Hi @HamidBee ,

 

Are you using "New column"?

tomfox_0-1647634611922.png

 

You might have clicked on "New measure" instead. Just a wild guess 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Yes I should have mentioned. I'm trying to create a measure instead of a calculated column. I'm dealing with alot of rows so I'm really trying to avoid using DAX calculated columns. Do you have any ideas on how I could ammend the following:

Petrol or Diesel = VAR Y = ADDCOLUMNS('Parking Data',"Petrol or Diesel", IF(('Parking Data'[Parking Amount])=[Petrol Price (£)],"Petrol","Diesel"))

RETURN Y



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.