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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
HCC
Frequent Visitor

NEED HELP WITH LOOKUPVALUE in Calculated Column

Hi Everyone,

 

So I am trying to write a DAX Command to show MoM% Change for several metros I am Analyzing. The core calculation is the ((employment for the current metro)/(The employment for the month prior for the corresponding metro)-1). I am far more proficient in Excel and have used sumifs to solve this calculation, but I need help writing the formula for power BI. Because January's dates do not have a value before, I want to return a blank value.

 

The Table name is 'Employment Analysis', see sample table below:

HCC_0-1671302699662.png

 

 

Here is the formula I tried to write: 

Metro MoM% Change = IFERROR(IF(ISBLANK('Employment Analysis'[Employment]),BLANK(),'Employment Analysis'[Employment]/LOOKUPVALUE('Employment Analysis'[Employment],'Employment Analysis'[Date],EDATE('Employment Analysis'[Date],-1),'Employment Analysis'[Employment],VALUE('Employment Analysis'[Area]))-1),BLANK())
 
Any help is much appreciated! Last item I need to calculate on my report!
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @HCC ,

 

I think you can try this code to create a calculated column.

MoM% Change =
VAR _PerviousDate =
    CALCULATE (
        SUM ( 'Employment Analysis'[Employment] ),
        FILTER (
            ALLEXCEPT ( 'Employment Analysis', 'Employment Analysis'[Metro] ),
            'Employment Analysis'[Date]
                = EOMONTH ( EARLIER ( 'Employment Analysis'[Date] ), -2 ) + 1
        )
    )
VAR _CurrentDate =
    CALCULATE ( SUM ( 'Employment Analysis'[Employment] ) )
VAR _Percentage =
    DIVIDE ( _CurrentDate, _PerviousDate ) - 1
RETURN
    IF ( _PerviousDate = BLANK (), BLANK (), _Percentage )

Result is as below.

RicoZhou_0-1671418622423.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @HCC ,

 

I think you can try this code to create a calculated column.

MoM% Change =
VAR _PerviousDate =
    CALCULATE (
        SUM ( 'Employment Analysis'[Employment] ),
        FILTER (
            ALLEXCEPT ( 'Employment Analysis', 'Employment Analysis'[Metro] ),
            'Employment Analysis'[Date]
                = EOMONTH ( EARLIER ( 'Employment Analysis'[Date] ), -2 ) + 1
        )
    )
VAR _CurrentDate =
    CALCULATE ( SUM ( 'Employment Analysis'[Employment] ) )
VAR _Percentage =
    DIVIDE ( _CurrentDate, _PerviousDate ) - 1
RETURN
    IF ( _PerviousDate = BLANK (), BLANK (), _Percentage )

Result is as below.

RicoZhou_0-1671418622423.png

 

Best Regards,
Rico Zhou

 

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

FreemanZ
Super User
Super User

hi @HCC 

try like:

MoM% :=
VAR _m = [Metro]
VAR _d = [Date]
VAR _e = 
MINX(
    FILTER(
        tbl,
        _m = [Metro]
            &&YEAR(_d)=YEAR([Date])
            &&MONTH(_d)=MONTH([Date])-1
    ),
    [Employment]
)
RETURN
FORMAT(DIVIDE([Employment] - _e, _e), "0.0%")

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors