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
monak1
Helper I
Helper I

[URGENT] Calculating a measure with Distinct Count for Maximum Date of Each Month

Hi all , I want to show a trended graph on month year basis. I have table called 'my main table' which has OrderDate,orderid and status I want the distinctcount of orderid for maximum date of each month for opened status. below is the example of the data

OrderDateOrderIDStatus
11/27/20231Opened
11/27/20232Opened
11/27/20233Opened
11/12/20231Opened
11/12/20231Opened
10/31/20231Opened
10/31/20232Opened
10/31/20233Opened
10/31/20234Opened
10/15/20231Opened
10/5/20232Opened
9/30/20231Opened
9/30/20232Opened
9/12/20231Opened
9/11/20232Closed
9/1/20234Opened

 

I want the below as output from previous data

Month YearCountStatus
Sep-232Opened
Oct-234Opened
Nov-233Opened

 

please note that I want a measure and not a calculated column. I want to use this measure within another measure which is as below YourSecondMeasure = VAR MaxDate = MAX('YourDateTable'[Date]) VAR PreviousDates = DATESINPERIOD(SlicerTable[Date], MaxDate, -SelectPeriodValue, MONTH) VAR Result = CALCULATE( [Firstmeasure], REMOVEFILTERS('YourDateTable'[Date]), KEEPFILTERS(PreviousDates), USERELATIONSHIP('YourDateTable'[Date], SlicerTable[Date]) )  .  

 

Below is the final output that I want

 

monak1_0-1701071480257.png

 

 

Please help ! thanks a lot in advance

 

1 ACCEPTED SOLUTION

thanks a lot for replying. It seems that I got the result .  I used the below measure   

measurename = VAR _maxdate = MAXX(
FILTER(
'my main table',
YEAR('my main table'[OrderDate]) = YEAR(MAX('my main table'[OrderDate])) &&
MONTH('my main table'[OrderDate]) = MONTH(MAX('my main table'[OrderDate])) &&
'my main table'[Status] = "Opened"
),
'my main table'[OrderDate]
)
RETURN
CALCULATE(
DISTINCTCOUNT('my main table'[OrderID]),
'my main table'[OrderDate] = _maxdate &&
'my main table'[Status] = "Opened"
)

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @monak1 ,

 

not sure if i fully get yo, try to:

1) add a calculated dates table like:

dates = 
ADDCOLUMNS(
    CALENDAR(MIN(data[OrderDate]), MAX(data[OrderDate])),
    "YYMM", FORMAT([Date], "mmm-yy"
    )
)

 

2) relate dates[date] to data[date] as 1:N

 

3) plot a visual with dates[yy-mm] column and a measure like:

MonthEndDistinctCount = 
VAR _maxdate = MAX(data[OrderDate])
VAR _list =
CALCULATETABLE(
    VALUES(data[OrderID]),
    data[OrderDate]=_maxdate,
    data[Status]="Opened"
)
RETURN COUNTROWS(_list)

 

it worked like:

FreemanZ_0-1701072674332.png

thanks a lot for replying. It seems that I got the result .  I used the below measure   

measurename = VAR _maxdate = MAXX(
FILTER(
'my main table',
YEAR('my main table'[OrderDate]) = YEAR(MAX('my main table'[OrderDate])) &&
MONTH('my main table'[OrderDate]) = MONTH(MAX('my main table'[OrderDate])) &&
'my main table'[Status] = "Opened"
),
'my main table'[OrderDate]
)
RETURN
CALCULATE(
DISTINCTCOUNT('my main table'[OrderID]),
'my main table'[OrderDate] = _maxdate &&
'my main table'[Status] = "Opened"
)

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.