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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Parvez933
Helper I
Helper I

How to calculate distinct count of last month and last to last month

Hi!

 

Can anyone please help in writing a DAX to calculate the Previous Month/Last Month, and Last to last month/last to previous month

 

Example:

Month ID

Jan       12

Jan        23

Feb      24

Feb      34

Mar      44

Mar      32

 

calculate(distinctcount(ID), feb???)

calculate(distinctcount(ID), jan???)

 

We tried

 

previousmonth() got Blank,

datesinperiod giving result for Feb but not for Jan

parelleperiod

currentmonth month(today())-1

 

but mostly not expected results

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Parvez933 

 

Previousmonth, datesinperiod and parelleperiod are all time intelligence functions which require a date column. Do you have date column in your table or only have the month name column as the sample data shows? In addition, if the first month in your table is January, the distinct count number of its previous month will be blank as there is no previous month data for it. Do you want to show blank for the earliest month or show other value for it?

 

Based on the current sample data, you can add a month number column to the table, then use the following measure to get the distinct count number of previous month for every month. 

Previous Count = 
VAR vCurrentMonth = MAX('Table'[MonthNumber])
RETURN
CALCULATE(DISTINCTCOUNT('Table'[ID]),ALL('Table'[Month]),'Table'[MonthNumber]=vCurrentMonth-1)

vjingzhang_0-1655108828098.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @Parvez933 

 

Previousmonth, datesinperiod and parelleperiod are all time intelligence functions which require a date column. Do you have date column in your table or only have the month name column as the sample data shows? In addition, if the first month in your table is January, the distinct count number of its previous month will be blank as there is no previous month data for it. Do you want to show blank for the earliest month or show other value for it?

 

Based on the current sample data, you can add a month number column to the table, then use the following measure to get the distinct count number of previous month for every month. 

Previous Count = 
VAR vCurrentMonth = MAX('Table'[MonthNumber])
RETURN
CALCULATE(DISTINCTCOUNT('Table'[ID]),ALL('Table'[Month]),'Table'[MonthNumber]=vCurrentMonth-1)

vjingzhang_0-1655108828098.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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