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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Henrik_99
Resolver I
Resolver I

DAX Power BI Desktop

Hi,

 

I am trying to show the difference between Panned Hrs Earned Hrsided by 2 (2= 2 next weeks) per activity based on last cut off date and add this data to the next 2 weeks (e.g. 2 next cut off dates) to the corresponding activity no.

 

The below example is illustrated in the table below, which also shows the calculations. If anyone could help me out that would be great 🙂

 

Untitled.png.

 

Rgds

Henrik

2 ACCEPTED SOLUTIONS
v-sihou-msft
Employee
Employee

@Henrik_99

 

In this scenario, you need to get the last non blank Panned-Earned's Cut_Off_Date, have it compare with current date to determine if it should return half of the last non blank Panned-Earned. Please refer to my sample below:

 

 

LastNonBlankDate =
CALCULATE (
    MAX ( 'Table'[Cut_Off_Date] ),
    FILTER (
        'Table',
        'Table'[Cut_Off_Date] < EARLIER ( 'Table'[Cut_Off_Date] )
            && 'Table'[ID] = EARLIER ( 'Table'[ID] )
            && 'Table'[Panned-Earned] <> BLANK ()
    )
)
DateDiff = 1*('Table'[Cut_Off_Date]-'Table'[LastNonBlankDate])
Column =
IF (
    'Table'[Panned-Earned] = 0,
    IF (
        'Table'[DateDiff] <= 14,
        CALCULATE (
            LASTNONBLANK ( 'Table'[Panned-Earned], 1 ),
            FILTER (
                'Table',
                'Table'[Cut_Off_Date] < EARLIER ( 'Table'[Cut_Off_Date] )
                    && 'Table'[ID] = EARLIER ( 'Table'[ID] )
            )
        )
            / 2,
        BLANK ()
    ),
    'Table'[Panned-Earned]
)

If you just want to build one column, it can be like:

 

Column =
IF (
    'Table'[Panned-Earned] = 0,
    IF (
        1
            * (
                'Table'[Cut_Off_Date]
                    - CALCULATE (
                        MAX ( 'Table'[Cut_Off_Date] ),
                        FILTER (
                            'Table',
                            'Table'[Cut_Off_Date] < EARLIER ( 'Table'[Cut_Off_Date] )
                                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
                                && 'Table'[Panned-Earned] <> BLANK ()
                        )
                    )
            )
            <= 14,
        CALCULATE (
            LASTNONBLANK ( 'Table'[Panned-Earned], 1 ),
            FILTER (
                'Table',
                'Table'[Cut_Off_Date] < EARLIER ( 'Table'[Cut_Off_Date] )
                    && 'Table'[ID] = EARLIER ( 'Table'[ID] )
            )
        )
            / 2,
        BLANK ()
    ),
    'Table'[Panned-Earned]
)

123.PNG

 

Regards,

 

View solution in original post

Hi Simon,

 

Thank you very much for your reply. I need to verify the solution in my desktop and give you a Feedback, thanks.

 

Regards

Henrik

View solution in original post

3 REPLIES 3
Henrik_99
Resolver I
Resolver I

Hi,

 

Just additional question. The soultion worked successfully for Calculated colums. What about for measures, see example below?

 

Thanks.

 

Rgds

H.

PowerBI_quest2.JPG

v-sihou-msft
Employee
Employee

@Henrik_99

 

In this scenario, you need to get the last non blank Panned-Earned's Cut_Off_Date, have it compare with current date to determine if it should return half of the last non blank Panned-Earned. Please refer to my sample below:

 

 

LastNonBlankDate =
CALCULATE (
    MAX ( 'Table'[Cut_Off_Date] ),
    FILTER (
        'Table',
        'Table'[Cut_Off_Date] < EARLIER ( 'Table'[Cut_Off_Date] )
            && 'Table'[ID] = EARLIER ( 'Table'[ID] )
            && 'Table'[Panned-Earned] <> BLANK ()
    )
)
DateDiff = 1*('Table'[Cut_Off_Date]-'Table'[LastNonBlankDate])
Column =
IF (
    'Table'[Panned-Earned] = 0,
    IF (
        'Table'[DateDiff] <= 14,
        CALCULATE (
            LASTNONBLANK ( 'Table'[Panned-Earned], 1 ),
            FILTER (
                'Table',
                'Table'[Cut_Off_Date] < EARLIER ( 'Table'[Cut_Off_Date] )
                    && 'Table'[ID] = EARLIER ( 'Table'[ID] )
            )
        )
            / 2,
        BLANK ()
    ),
    'Table'[Panned-Earned]
)

If you just want to build one column, it can be like:

 

Column =
IF (
    'Table'[Panned-Earned] = 0,
    IF (
        1
            * (
                'Table'[Cut_Off_Date]
                    - CALCULATE (
                        MAX ( 'Table'[Cut_Off_Date] ),
                        FILTER (
                            'Table',
                            'Table'[Cut_Off_Date] < EARLIER ( 'Table'[Cut_Off_Date] )
                                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
                                && 'Table'[Panned-Earned] <> BLANK ()
                        )
                    )
            )
            <= 14,
        CALCULATE (
            LASTNONBLANK ( 'Table'[Panned-Earned], 1 ),
            FILTER (
                'Table',
                'Table'[Cut_Off_Date] < EARLIER ( 'Table'[Cut_Off_Date] )
                    && 'Table'[ID] = EARLIER ( 'Table'[ID] )
            )
        )
            / 2,
        BLANK ()
    ),
    'Table'[Panned-Earned]
)

123.PNG

 

Regards,

 

Hi Simon,

 

Thank you very much for your reply. I need to verify the solution in my desktop and give you a Feedback, thanks.

 

Regards

Henrik

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.