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
UditJ
Helper III
Helper III

IF ELSE THEN Condition in Power BI

Need to replicate the below formulas in power bi:

IF
[Campaign Start Date] = [Date]
THEN
[Campaign Name]
ELSE
NULL
END



IF
COUNTD([Campaign Launching]) = 0
THEN NULL
ELSE
COUNTD([Campaign Launching])
END

Any suggestions ?

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @UditJ ,

I created some data:

Table1:

vyangliumsft_0-1671697149556.png

Table2:

vyangliumsft_1-1671697149558.png

Are you referring to COUNTD in Tableau, this function returns the number of items in a group , nULL values are not counted.

How to use Count and Count Distinct in Tableau (rigordatasolutions.com)

Here are the steps you can follow:

1. Create measure.

The first function:

IF =
IF(
    'Table'[Campaign Start Date]='Table'[Date],
    'Table'[Campaign Name],BLANK())

vyangliumsft_2-1671697149558.png

The second function:

It can be judged without IF, and it will automatically be displayed as Blank() when it does not match.

CountD =
CALCULATE(
    DISTINCTCOUNT('Table2'[Campaign Launching]),
    FILTER(ALL(Table2),'Table2'[ID]=EARLIER('Table2'[ID])&&'Table2'[Campaign Launching]<>BLANK()))

vyangliumsft_3-1671697149559.png

 

Best Regards,

Liu Yang

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-yangliu-msft
Community Support
Community Support

Hi  @UditJ ,

I created some data:

Table1:

vyangliumsft_0-1671697149556.png

Table2:

vyangliumsft_1-1671697149558.png

Are you referring to COUNTD in Tableau, this function returns the number of items in a group , nULL values are not counted.

How to use Count and Count Distinct in Tableau (rigordatasolutions.com)

Here are the steps you can follow:

1. Create measure.

The first function:

IF =
IF(
    'Table'[Campaign Start Date]='Table'[Date],
    'Table'[Campaign Name],BLANK())

vyangliumsft_2-1671697149558.png

The second function:

It can be judged without IF, and it will automatically be displayed as Blank() when it does not match.

CountD =
CALCULATE(
    DISTINCTCOUNT('Table2'[Campaign Launching]),
    FILTER(ALL(Table2),'Table2'[ID]=EARLIER('Table2'[ID])&&'Table2'[Campaign Launching]<>BLANK()))

vyangliumsft_3-1671697149559.png

 

Best Regards,

Liu Yang

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

VahidDM
Super User
Super User

Hi @UditJ 

First check this links:
https://learn.microsoft.com/dax/if-function-dax?WT.mc_id=DP-MVP-5004936

https://learn.microsoft.com/dax/blank-function-dax?WT.mc_id=DP-MVP-5004936

https://learn.microsoft.com/dax/date-function-dax?WT.mc_id=DP-MVP-5004936

 

then use below with DAX:

 

1- 
IF([Campaign Start Date] = [Date],[Campaign Name],blank())


 

2-

IF (COUNTD([Campaign Launching]) = 0,blank(),COUNTD([Campaign Launching]))

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

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

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.