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
Fcoatis
Post Patron
Post Patron

Convert calculated column into measure

Hello, I have the following calculated column in a table called 'Admin':

 

Diff = [Quantidade]-LOOKUPVALUE(
					Admin[Quantidade],Admin[Código],[Código],Admin[Data],
					CALCULATE(
						Max(Admin[Data]),
						FILTER(
							Admin,Admin[Código]=EARLIER(Admin[Código])&&Admin[Data]<EARLIER(Admin[Data])
						)
					)
				)

I can´t figure it out as a measure. Please help

 

TIA

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

@Fcoatis , you may want to try,

Delta = 
VAR __dt = MAX ( Admin[Data] )
VAR __tb =
    TOPN (
        1,
        CALCULATETABLE ( Admin, ALLEXCEPT ( Admin, Admin[Código] ), Admin[Data] < __dt ),
        Admin[Data]
    )
RETURN
    MAX ( Admin[Quantidade] ) - MAXX ( __tb, Admin[Quantidade] )

Screenshot 2021-02-19 204603.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

5 REPLIES 5
negi007
Community Champion
Community Champion

@Fcoatis When you use column or calculated column in your measure, you have to use it with some aggreage function like sum, max, min, count etc. 

in calculated column you can use directly column name without using aggreage function.

 

for specify solution of your problem, you may share your powerbi file.




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



Proud to be a Super User!


Follow me on linkedin

amitchandak
Super User
Super User

@Fcoatis ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

@amitchandak Here it is.

 

Thank you

CNENFRNL
Community Champion
Community Champion

@Fcoatis , you may want to try,

Delta = 
VAR __dt = MAX ( Admin[Data] )
VAR __tb =
    TOPN (
        1,
        CALCULATETABLE ( Admin, ALLEXCEPT ( Admin, Admin[Código] ), Admin[Data] < __dt ),
        Admin[Data]
    )
RETURN
    MAX ( Admin[Quantidade] ) - MAXX ( __tb, Admin[Quantidade] )

Screenshot 2021-02-19 204603.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thank you, thats it.

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.