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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
vickyprudhvi
Helper IV
Helper IV

Dax Measure help

DateDimensionIDJobCloseDatePolicyNumberBranchIDJob
201607017/1/2016 0:00A1Submission
201607027/2/2016 0:00A3Policy Change
201607027/3/2016 1:00C4Reinstatement
201607037/3/2016 1:00A5Cancellation
201607037/3/2016 2:00B7Cancellation
201607037/3/2016 3:00B8Cancellation
201607037/3/2016 4:00A6Cancellation
201607047/5/2016 0:00A9Reinstatement

Hi Friends,

I am trying to write a measure in tabular which gets me count of all the policies whose latest Job is "Cancellation"

latest Job is based on JobCloseDate.

For example

IN Power BI Desktop If I have a slicer on Td_Date[CalendarDate](It is connected to this table using DateDimensionID)

If I select 07/04/2016 on the slicer then the totalCount should be 1

If I select 07/03/2016 on the slicer then the totalCount should be 2

 

Kindly help me out on this.

9 REPLIES 9
v-haibl-msft
Microsoft Employee
Microsoft Employee

@vickyprudhvi

 

In you provided table, the type of DateDimensionID is not standard Date type, so I create a new date column with following formula and create relationship with calendar table with this column.

Date = 
DATE ( LEFT ( Table1[DateDimensionID], 4 ), MID ( Table1[DateDimensionID], 5, 2 ), MID ( Table1[DateDimensionID], 7, 2 ) )

Then we can create another measure to display the result in the card.

Measure = 
VAR CountCurrentDay =
    CALCULATE (
        DISTINCTCOUNT ( Table1[PolicyNumber] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Date] = MAX ( Td_Date[Date] )
                && Table1[Job] = "Cancellation"
        )
    )
RETURN
    (
        IF (
            CountCurrentDay > 0,
            CountCurrentDay,
            CALCULATE (
                DISTINCTCOUNT ( Table1[PolicyNumber] ),
                FILTER (
                    ALL ( Table1 ),
                    Table1[JobCloseDate]
                        = CALCULATE (
                            MAX ( Table1[JobCloseDate] ),
                            FILTER ( ALL ( Table1 ), Table1[JobCloseDate] < MAX ( Table1[Date] ) )
                        )
                        && Table1[Job] = "Cancellation"
                )
            )
        )
)

Dax Measure help_1.jpg

 

Best Regards,

Herbert

@v-haibl-msft

Thank you for ur detail reply.

What i would like to see is

on 07/04/2016 it should show me 2

and not 1

if I select a 07/04/2016. It should count all the policies from the start to that specific date(which is 07/04/2016)

@vickyprudhvi

 

Please try to use the following updated measure.

Measure_Update = 
VAR CountCurrentDay =
    CALCULATE (
        DISTINCTCOUNT ( Table1[PolicyNumber] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Date] = MAX ( Td_Date[Date] )
                && Table1[Job] = "Cancellation"
        )
    )
RETURN
    (
        IF (
            CountCurrentDay > 0,
            CountCurrentDay,
            CALCULATE (
                DISTINCTCOUNT ( Table1[PolicyNumber] ),
                FILTER (
                    ALL ( Table1 ),
                    Table1[Date] < MAX ( Td_Date[Date] )
                        && Table1[Job] = "Cancellation"
                )
            )
        )
    )

 

Best Regards,

Herbert

KGrice
Memorable Member
Memorable Member

Using your sample data, I'm able to come up with 2 if I select 7/3/2016, but 0 if I select 7/4/2016. I think that's accurate from what I can see in the table. On 7/4/2016, the only PolicyNumber is A, and it's most recent Job is Reinstatement. With none of the dates selected, I get this for a final product:

 

PolicyNumber.PNG

 If that looks good, then I did it with 3 measures. You don't have to display all of them in your end result.

 

MostRecentJob = IF(HASONEVALUE(TableName[PolicyNumber]), 
CALCULATE(
VALUES(TableName[Job]),
FILTER(ALLEXCEPT(TableName, TableName[PolicyNumber]), TableName[JobCloseDate]=MAX(TableName[JobCloseDate]))
), BLANK())

 

isCancelled = IF([MostRecentJob]="Cancellation", 1, 0)

 

CancelledPolicies = SUMX(VALUES(TableName[PolicyNumber]), [isCancelled])

 

 

 

 

 

 

 

@KGrice

if we select 7/4/2016 on slcier then  it should consider all claims until 7/4/2016

and not just those claims that are on 7/4/2016

Capture.JPG

@KGrice

this is how I want to see.

but as of 7/4/2016 it should show 1 but shows 0

Hi @vickyprudhvi. What I provided above will work for using with a card without further modification:

 

CancelledPolicies.PNG

 What I'm not sure of is why selecting 7/4/2016 would result in 1 with the data provided. The only Policy on that date is A, with a Job of Reinstatement.

 

Hi @KGrice

The table is Type 2  fact so only delta's and new Policies will be added. so as of 07/04/2016 it should consider all the claims whose max  jobclosedate has Job type cancellation.

@KGrice

Thank you for your reply

I want to just see result using card visual that means

measure is alone and not used along PolicyNumber.

 

hope u understood

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.