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
salim123
Frequent Visitor

Calculate a measure that checks if data is blank and If so use previous month avg to do calcuations

Hello every one,

I am posting this for the second time, since I had no help in the first time, any remark would be helpful.

So I am new to dax and I am writing this measure that calculates a weighted value (SUMPROD(volume, TS) divided bySUM(Volume)), but the problem is that TS values are not there every day, so I have to multiply the volume with TS avg of the previuos month, I see that my reasoning is right bu something dosen't seem to work.
Here is My measure :

TS Ponderee (Madcap) =

        DIVIDE(
            SUMX('all years data',
            var c=0
            return
                 if('all years data'[T/S]<>BLANK(),'all years data'[Vol L]*'all years data'[T/S], 'all years data'[Vol L]*[previous_month_ts])
            ),
            SUMX(
                'all years data', 'all years data'[Vol L]
            )
        )

The previous month measure:

previous_month_ts = Calculate(
                        [T/S avg],
                        DATEADD(DateAnalyse[Date],-30,DAY)
                    )

Here is a piece of my data , as you can T/S is not there every time:

salim123_2-1662733660534.png

And here what I get when I show data as a table:

salim123_3-1662733991713.png

Any remark would be helpful.
thank you

 

 

1 ACCEPTED SOLUTION

Thank you for all your feedbacks.

Finally I  found the solution, what I did is that I added a calculated column where I store the multiplication of Volume and T/S:

salim123_0-1663527114739.png

And then I used it with the formula as follows:

TS Ponderee (Madcap) =
VAR PreviousMonthTS = [previous_month_ts]
VAR Numerator =
    SUMX (
        'all years data',
        IF (
            'all years data'[T/S] <> BLANK (),
            'all years data'[volume*T\S],
            'all years data'[Vol L] * PreviousMonthTS
        )
    )
VAR Denominator =
    SUMX ( 'all years data', 'all years data'[Vol L] )
RETURN
    DIVIDE ( Numerator, Denominator )

 

Thank alot for your efforts.

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

Hi @salim123 
Please try

TS Ponderee (Madcap) =
VAR PreviousMonthTS = [previous_month_ts]
VAR Numerator =
    SUMX (
        'all years data',
        IF (
            'all years data'[T/S] <> BLANK (),
            'all years data'[Vol L] * 'all years data'[T/S],
            'all years data'[Vol L] * PreviousMonthTS
        )
    )
VAR Denominator =
    SUMX ( 'all years data', 'all years data'[Vol L] )
RETURN
    DIVIDE ( Numerator, Denominator )

Thank you for your feedback.

I tried the formula provided in your response, but it is still the same problem:

salim123_0-1663524016357.png

 

@salim123 
Previous TS is measure right?

Yes and here is its formula:

 

previous_month_ts = Calculate(
                        AVERAGE([T/S]),
                        DATEADD(DateAnalyse[Date],-30,DAY)
                    )

@salim123 
Please test the following 

TS Ponderee (Madcap) =
SUMX ( 'all years data', IF ( 'all years data'[T/S] <> BLANK (), 1, 0 ) )

Here is what it outputs:

salim123_0-1663525713607.png

 

@salim123 

In the first measure I shared

RETURN 

    Denominator

Thank you for all your feedbacks.

Finally I  found the solution, what I did is that I added a calculated column where I store the multiplication of Volume and T/S:

salim123_0-1663527114739.png

And then I used it with the formula as follows:

TS Ponderee (Madcap) =
VAR PreviousMonthTS = [previous_month_ts]
VAR Numerator =
    SUMX (
        'all years data',
        IF (
            'all years data'[T/S] <> BLANK (),
            'all years data'[volume*T\S],
            'all years data'[Vol L] * PreviousMonthTS
        )
    )
VAR Denominator =
    SUMX ( 'all years data', 'all years data'[Vol L] )
RETURN
    DIVIDE ( Numerator, Denominator )

 

Thank alot for your efforts.

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.