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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.