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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
roopa_123
Helper I
Helper I

DAX-How to use GROUPBY and IF in DAX

Hi PowerBi Community,

I need a help on my query.

I have created a new table based on main table(PipelineRuns) using the below DAX query.

FailedRuns= FILTER(FILTER(
GROUPBY(
PipelineRuns,
PipelineRuns[SourceInstance],
PipelineRuns[PipelineName],
PipelineRuns[status],
"LatestFailedRuns",
MAXX(CURRENTGROUP(),PipelineRuns[start]),
"TotalFailedRuns",
COUNTX(CURRENTGROUP(),PipelineRuns[start])),
PipelineRuns[status]="Failed"),
PipelineRuns[PipelineName]="mypipelinename")

I've used a table visual as below.

roopa_123_0-1649700107846.png

As per my requirement, I need to get the report visual in the below format i.e., the 'TotalFailedRuns' should be filled with '0' if there is no data for 'LatestFailedRuns'

roopa_123_1-1649700220980.png

 

How can this be achieved using DAX? / Can we use GROUPBY and IF condition together to achieve the above requirement? If there is any other way, kindly suggest.
Help is appreciated! Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @roopa_123 ,

 

According to this: "TotalFailedRuns" column should show zeros(0) instead of blank 

 

Simply, you could add "+0" to the end of the [TotalFailedRuns] measure, for example:

Recording 2022-04-14 at 12.00.18.gif

Or use IF() to replace blank value:

TotalFailedRuns = 
var _total=SUM('Table (2)'[Value])
return IF(_total=BLANK(),0,_total)

Eyelyn9_0-1649908927118.png

Best Regards,
Eyelyn Qin
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

5 REPLIES 5
Anonymous
Not applicable

Hi @roopa_123 ,

 

According to this: "TotalFailedRuns" column should show zeros(0) instead of blank 

 

Simply, you could add "+0" to the end of the [TotalFailedRuns] measure, for example:

Recording 2022-04-14 at 12.00.18.gif

Or use IF() to replace blank value:

TotalFailedRuns = 
var _total=SUM('Table (2)'[Value])
return IF(_total=BLANK(),0,_total)

Eyelyn9_0-1649908927118.png

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

Greg_Deckler
Community Champion
Community Champion

@roopa_123 I *think* you want:

FailedRuns= 
FILTER(
  GROUPBY(
    FILTER(PipelineRuns,PipelineRuns[PipelineName]="mypipelinename"),
    PipelineRuns[SourceInstance],
    PipelineRuns[PipelineName],
    PipelineRuns[status],
    "LatestFailedRuns",MAXX(CURRENTGROUP(),PipelineRuns[start]),
    "TotalFailedRuns",COUNTX(CURRENTGROUP(),PipelineRuns[start])
  ),
  PipelineRuns[status]="Failed"
)

Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

Please find the below sample data and expectedoutput.
SampleData:

PipelineNamestartstatussourceInstance
PL_AB28-02-2022 10:18:22SucceededABC
PL_CD28-02-2022 10:18:41SucceededDEF
PL_EF28-02-2022 10:18:54SucceededXYZ
PL_GH28-02-2022 10:19:31FailedABC
PL_AB28-02-2022 10:19:07SucceededABC
PL_AB1/3/22 10:10FailedABC
PL_AB1/3/22 10:14SucceededABC
PL_AB1/3/22 10:23FailedABC
PL_EF1/3/22 10:10FailedDEF
PL_EF1/3/22 10:10FailedDEF
PL_EF1/3/22 10:10FailedDEF
PL_GH19/3/2022  10:20SucceededABC
PL_GH19/3/2022  6:07SucceededDEF
PL_GH19/3/2022  6:10SucceededXYZ
PL_GH1/12/22 10:10FailedXYZ
PL_GH1/13/22 10:10FailedXYZ


ExpectedOutput:

SourceInstanceLatesSuccessfulRunsTotal SuccessfulRunsLatestFailureRunsTotalFailedRuns
ABC19-3-2022 10:207031/3/22 10:103
DEF19-3-2022 6:073 0
XYZ19-3-2022 6:103 0



@roopa_123 Maybe something like this although I am still not certain of the logic of how to calculate the Total Failed Runs.

Measure = 
    VAR __Table =
        ADDCOLUMNS(
            FILTER(
                ADDCOLUMNS(
                    GROUPBY('Table2',[PipelineName]),
                    "LastFailed",MAXX(FILTER('Table2',[PipelineName] = EARLIER([PipelineName]) && [status] = "Failed"),[start]),
                    "LastSucceed",MAXX(FILTER('Table2',[PipelineName] = EARLIER([PipelineName]) && [status] = "Succeeded"),[start])
                ),
                [LastFailed] > [LastSucceed]
            ),
            "Count",COUNTROWS(FILTER('Table2',[PipelineName] = EARLIER([PipelineName]) && [status] = "Failed"))
        )
RETURN
    SUMX(__Table,[Count])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

Thanks for your reply.

I've actually developed the model and built report and it is working as expected but only the thing needed to show in my report is that "TotalFailedRuns" column should show zeros(0) instead of blank on my table visuals.

roopa_123_1-1649745449345.png

Expected report should look something like below:

roopa_123_3-1649745541662.png


How can this be achieved using DAX? Thanks in advance!

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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