Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
If i have a pivot or table with Year / Month ;
I want to count the previous number of months present so not just the month number
as some do not have any data so are not present
so if i had
Jan sales 1
March sales 2
May sales 3
so the best i have so far is ;
Count Previous Months:=VAR Myear =
IF( HASONEVALUE( 'Calendar'[Year]),VALUES( 'Calendar'[Year]))
VAR Mmonth =
IF (HASONEVALUE( 'Calendar'[Month Number]), VALUES('Calendar'[Month Number]))
RETURN
CALCULATE (
DISTINCTCOUNT ( 'Calendar'[Month Number]),
FILTER(ALL('Calendar'), 'Calendar'[Month Number]<= Mmonth && 'Calendar'[Year] = Myear))so this counts the months regardless of whether there are 'sales' present
Richard
Solved! Go to Solution.
Hi @Dicken
Can you please try this measure
Count Previous Months=
CALCULATE(DISTINCTCOUNT('Calendar'[Month Number]),FILTER(ALL('Calendar'),
'Calendar'[Date]<=MAX('Calendar'[Date])),
KEEPFILTERS('Sales'))
hi @Dicken ,
try like:
Count Previous Months:=
VAR Myear =
IF(
HASONEVALUE( 'Calendar'[Year]),
VALUES( 'Calendar'[Year])
)
VAR Mmonth =
IF (HASONEVALUE( 'Calendar'[Month Number]), VALUES('Calendar'[Month Number]))
RETURN
CALCULATE (
COUNTROWS ( 'sales'),
FILTER(ALL('Calendar'), 'Calendar'[Month Number]<= Mmonth && 'Calendar'[Year] = Myear))
hi @Dicken ,
try like:
Count Previous Months:=
VAR Myear =
IF(
HASONEVALUE( 'Calendar'[Year]),
VALUES( 'Calendar'[Year])
)
VAR Mmonth =
IF (HASONEVALUE( 'Calendar'[Month Number]), VALUES('Calendar'[Month Number]))
RETURN
CALCULATE (
COUNTROWS ( 'sales'),
FILTER(ALL('Calendar'), 'Calendar'[Month Number]<= Mmonth && 'Calendar'[Year] = Myear))
It may work.
Count Previous Months :=
CALCULATE(
DISTINCTCOUNT( 'Calendar'[Month Number] ),
FILTER(
ALL( 'Calendar' ),
'Calendar'[Date] <= MAX( 'Calendar'[Date] )
),
KEEPFILTERS( 'Sales' )
)
Hi @Dicken
Can you please try this measure
Count Previous Months=
CALCULATE(DISTINCTCOUNT('Calendar'[Month Number]),FILTER(ALL('Calendar'),
'Calendar'[Date]<=MAX('Calendar'[Date])),
KEEPFILTERS('Sales'))
Thank you all, I'll work through all of them.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 44 | |
| 43 | |
| 38 | |
| 18 | |
| 16 |
| User | Count |
|---|---|
| 67 | |
| 63 | |
| 30 | |
| 30 | |
| 23 |