Reply
o59393
Post Prodigy
Post Prodigy
Partially syndicated - Outbound

IF with measure

Hi all

 

I am trying to create an if measure like this:

 

IF(
    HASONEVALUE(facilities[bottler])="ABI El Salvador",
    CALCULATE(
        [Complaints],
        'date'[MM YYYY]=DATE(2020,11,1),'date'[MM YYYY]=DATE(2020,12,1)),
        CALCULATE([Complaints],
        PREVIOUSYEAR('date'[date]))
)

 

I am using hasonvalue, followed by the column "bottler" equals to ABI El Salvador.

 

The measure seems to work, but the visual is:

 

sadasd1133.JPG

 

Any idea how to get it right?

 

Thanks.

 

 

1 ACCEPTED SOLUTION

Syndicated - Outbound

Hi,

Try this measure

=

IF(SELECTEDVALUE(facilities[bottler])="ABI El Salvador",CALCULATE([Complaints],
DATESBETWEEN('date'[date],date(year(min('date'[date]))-1,11,1),date(year(min('date'[date]))-1,12,31))),CALCULATE([Complaints],PREVIOUSYEAR('date'[date])))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
HarishKM
Power Participant
Power Participant

Syndicated - Outbound

@o59393  Hey ,

Use this one 

 

IF(
SELECTEDVALUE(facilities[bottler])="ABI El Salvador",
CALCULATE(
[Complaints],
'date'[MM YYYY]=DATE(2020,11,1),'date'[MM YYYY]=DATE(2020,12,1)),
CALCULATE([Complaints],
PREVIOUSYEAR('date'[date]))

Try this and let me know .

 

or try this .

Calculate(calculate([Complaints],sameperiodlastyear(date[date]) , facilities[bottler])="ABI El Salvador" ) 

 

Syndicated - Outbound

hi @HarishKM 

 

In fact I had tried that one. But returns a blank only.

 

I guess it should be solved by some kind of time intelligence formula.


THanks

d_gosbell
Super User
Super User

Syndicated - Outbound

Try using the SELECTEDVALUE function instead of HASONEVALUE

Syndicated - Outbound

Hi @d_gosbell 

 

It worked however it shows blank and it shouldn't 😞

 

asdasd2.JPG

 

 

Do you if it's possible to tell the time intelligence function "previous year" to calculate only the last 2 months?

 

In this case, calculate the previous year's last 2 months (november 2020 and december 2020)

 

The dax is below:

 

CC PY =

IF(
SELECTEDVALUE(facilities[bottler])="ABI El Salvador",
CALCULATE(
[Complaints],
PREVIOUSYEAR('date'[date])), -- this one to calculate last 2 months 
CALCULATE([Complaints],
PREVIOUSYEAR('date'[date]))
)
 
Thanks!

Syndicated - Outbound

Hi,

Does this measure work?

CC PY = IF(SELECTEDVALUE(facilities[bottler])="ABI El Salvador",CALCULATE([Complaints],
DaTESBETWEEN('date'[date],edate(min('date'[date]),-1),max('date'[date]))),CALCULATE([Complaints],PREVIOUSYEAR('date'[date])))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Syndicated - Outbound

Hi @Ashish_Mathur 

 

I didn't. Let me give you an example:

 

221312321.JPG

 

Let's say the yellow cell is a date slicer. Since the date contains present year, the measure should calculate the previous year for november 2020 and december 2020 if "ABI El Salvador" is selected.

 

There must be something wrong in the red part of the DAX:

 

CC PY =
IF(
SELECTEDVALUE(facilities[bottler])="ABI El Salvador",
CALCULATE([Complaints],
DATESBETWEEN('date'[date],
edate(
min('date'[date]),-1),
max('date'[date]))),
CALCULATE([Complaints],
PREVIOUSYEAR('date'[date])
)
)

 

I attach the excel. https://1drv.ms/x/s!ApgeWwGTKtFdh0Qw3qTRuW4VTI8D?e=ZidRvL

 

Let me know if you have questions.

 

Thanks!

 

 

 

Syndicated - Outbound

Hi,

Try this measure

=

IF(SELECTEDVALUE(facilities[bottler])="ABI El Salvador",CALCULATE([Complaints],
DATESBETWEEN('date'[date],date(year(min('date'[date]))-1,11,1),date(year(min('date'[date]))-1,12,31))),CALCULATE([Complaints],PREVIOUSYEAR('date'[date])))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Syndicated - Outbound

Awsome @Ashish_Mathur 

 

Thanks a million all of you, have a great weekend.

Syndicated - Outbound

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)