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
mmace1
Impactful Individual
Impactful Individual

Adding Index Column to Calendar Table that was created in DAX (so no Power Query)

Hi, 

 

I have a Calendar Table that I just made in DAX via the CALENDAR function. 

 

I'd like to add an Index column to it - just a 1,2,3,4, etc.  Since I made it in DAX, and not Power Query, there's no ready-made way to do this.   What would be the easiest way to do it in DAX?  Capture.PNG

 

 

1 ACCEPTED SOLUTION
anandav
Skilled Sharer
Skilled Sharer

@mmace1

 

Try the below DAX in New Column.

 

Row Index Column =
CALCULATE(
    COUNTROWS(TCalendar),
    FILTER(All(TCalendar), TCalendar[Date] <= EARLIER(TCalendar[Date]))

)

 

Hope this helps.

If this solves your problem please mark as solution.

View solution in original post

3 REPLIES 3
JulioGadioli
Frequent Visitor

Great solution, I want to share all the code and how I managed to index Year/Month:

Calendario =
var dataminima1 = DATE(YEAR(MIN('ReportCashflowSA'[Data])),1,1)
var dataminima2 = DATE(YEAR(MIN('Report_CashflowSA'[DtCompet_Final])),1,1)
var dataminima3 = DATE(YEAR(MIN('Report_CashflowSA'[DtCompet_Inicial])),1,1)
var datamin1 = MIN(dataminima1,dataminima2)
var datamin2 = MIN(dataminima2, dataminima3)
var datamin = MIN(datamin1,datamin2)
var datamaxima1 = DATE(YEAR(MAX('Report_CashflowSA'[Data])),12,31)
var datamaxima2 = DATE(YEAR(MAX('Report_CashflowSA'[DtCompet_Final])),12,31) --
var datamaxima3 = DATE(YEAR(MAX('Report_CashflowSA'[DtCompet_Inicial])),12,31)
var datamax1 = MAX(datamaxima1,datamaxima2)
var datamax2 = MAX(datamaxima2, datamaxima3)
var datamax = MAX(datamax1,datamax2)
return
ADDCOLUMNS (CALENDAR(datamin, datamax),
"DateAsInteger", FORMAT ( [date], "YYYYMMDD" ),
"Ano", YEAR ( [date] ), "MonthNo", FORMAT ( [date], "MM" ),
"AnoMesNum", FORMAT ( [date], "YYYY/MM" ),
"AnoMes", FORMAT ( [date], "YYYY/mmm" ),
"MêsCurto", FORMAT ( [date], "mmm" ),
"MêsLongo", FORMAT ( [date], "mmmm" ),
"SemanaNum", WEEKDAY ( [date] ),
"SemanaDia", FORMAT ( [date], "dddd" ),
"SemanaDiaCurto", FORMAT ( [date], "ddd" ),
"Trimestre", "T" & FORMAT ( [date], "Q" ),
"AnoTrimestre", FORMAT ( [date], "YYYY" ) & "/T" & FORMAT ( [date], "Q" ))
And add column:
AnoMes Index Column =
CALCULATE(
    COUNTROWS(Calendario),
    FILTER(All(Calendario), Calendario[AnoMesNum] <= EARLIER(Calendario[AnoMesNum]))
)
anandav
Skilled Sharer
Skilled Sharer

@mmace1

 

Try the below DAX in New Column.

 

Row Index Column =
CALCULATE(
    COUNTROWS(TCalendar),
    FILTER(All(TCalendar), TCalendar[Date] <= EARLIER(TCalendar[Date]))

)

 

Hope this helps.

If this solves your problem please mark as solution.

mmace1
Impactful Individual
Impactful Individual

That's a nice way to do it - thanks!

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.