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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

EARLIER function error - get count of IDs by month dynamically with slicer

Hello, I hope some help about this.

 

I managed to get the follwing graph

Captura de pantalla (66).png

For this, I first created a column in ventas table with this Dax formula:

(This column is only a count of total sales or total ids in each month) 

Venta Mens. = CALCULATE (
COUNT(ventas[id]),
FILTER(ventas, FORMAT(ventas[date], "yyyymm") = FORMAT(EARLIER(ventas[date]), "yyyymm") )
)
 
Second, I use that column in this measure to get the mentioned graph:
Venta Mens. Cosecha = CALCULATE (
MAX(ventas[Venta Mens.]),
USERELATIONSHIP(ventas[date], trx_diario[dia_venta])
)

 

My problem comes because in this way, my measure is "static" and I need to be able to change it in base a slicer that have the segment column of segmentos table.

So I tried to put a single masure like this (using ALLSELECTED function), but I get error with EARLIER function (and I'm not really sure if this will give me the desire output that could be filtered with segment slicer)

Venta Mens. Cosecha =
var Venta_Mens. = CALCULATE (
COUNT(ventas[id]),
FILTER(ALLSELECTED(ventas), FORMAT(ventas[date], "yyyymm") = FORMAT(EARLIER(ventas[date]), "yyyymm") ))
return
CALCULATE (
MAX(Venta_Mens.),
USERELATIONSHIP(ventas[date], trx_diario[dia_venta])
)

Captura de pantalla (67).png

 

I hope my explanation is enough and someone could give some help. Feel free to ask more details if necessary.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Yes, I tried the column you suggested, I even tried that before posting

 

But, finally I managed to get what I needed. Here the metric:

 

Venta Mens. Cosecha =
CALCULATE (
DISTINCTCOUNT(ventas[id]),
FILTER(ALLSELECTED( ventas[Trunc date]),
ventas[Trunc date]= LASTDATE( ventas[Trunc date])
),
USERELATIONSHIP(ventas[date], trx_diario[dia_venta]), ALLSELECTED(trx_diario[maduracion])
)

View solution in original post

6 REPLIES 6
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

I would suggest you first create a column in your ventas table using below syntax:

Year-month=FORMAT(ventas[date], "yyyymm") 

Then create a measure as below:

Venta Mens. Cosecha =
var Venta_Mens. = CALCULATE (
COUNT(ventas[id]),
FILTER(ALLSELECTED(ventas),ventas[Year-month] = MAX(ventas[Year-month]))
return
CALCULATE (
MAX(Venta_Mens.),
USERELATIONSHIP(ventas[date], trx_diario[dia_venta])
)

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

 

Anonymous
Not applicable

Hello, sorry for delay, but this is the same as @amitchandak answer and as I said before, I get error in MAX function (you can see it in the next image). I still don't get how to fix it.

f.png

Hi @Anonymous ,

 

Have you first created a column as I suggested before?

Year-month=FORMAT(ventas[date], "yyyymm") 

If you still get errors,would you pls provide some dummy data for test?

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

Anonymous
Not applicable

Yes, I tried the column you suggested, I even tried that before posting

 

But, finally I managed to get what I needed. Here the metric:

 

Venta Mens. Cosecha =
CALCULATE (
DISTINCTCOUNT(ventas[id]),
FILTER(ALLSELECTED( ventas[Trunc date]),
ventas[Trunc date]= LASTDATE( ventas[Trunc date])
),
USERELATIONSHIP(ventas[date], trx_diario[dia_venta]), ALLSELECTED(trx_diario[maduracion])
)
amitchandak
Super User
Super User

@Anonymous , You can use allselected and MAx in place earlier in a measure

 

Venta Mens. Cosecha =
var Venta_Mens. = CALCULATE (
COUNT(ventas[id]),
FILTER(ALLSELECTED(ventas), FORMAT(ventas[date], "yyyymm") = FORMAT(MAX(ventas[date]), "yyyymm") ))
return
CALCULATE (
MAX(Venta_Mens.),
USERELATIONSHIP(ventas[date], trx_diario[dia_venta])
)

 

what are you trying to do here.

 

if you need last month data use time intelligence

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak Thanks for your suggestion.

I have to say that searching about EARLIER function I found what you say (replacing EARLIER by MAX), but the problem it that using the formula you suggest gives me error "The MAX function only accepts a column reference as an argument." (But this function is what I need, problem is the given error)

I don't get how to solve this error because as I understand so far, I only passing one argument to MAX function, but get error anyway.

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors