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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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