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
VDS9
Frequent Visitor

Help required with index

Hi I am trying to create a lesson index so that I have them in the correct order when looking at a linechart. Unfortunately isnt as straight forward as there are a couple of exceptions.

 

This data comes from a folder with several identical excel files (1 file p/week).

In each file there are 9 sheets. The first 3 sheets have only 12 "Lessons"

MAMRM1M2MBM3M4MLM5M6MEMDTATRT1T2TBT3T4TLT5T6TETDWAWRW1W2WBW3W4WLW5W6WEWDTHATHRTH1TH2THBTH3TH4THLTH5TH6THETHD

 

The other 6 sheets have 13 "lessons"

MAMRM1M2M3MBM4M5MLM6M7MEMDTATRT1T2T3TBT4T5TLT6T7TETDWAWRW1W2W3WBW4W5WLW6W7WEWDTHATHRTH1TH2TH3THBTH4TH5THLTH6TH7THETHD

 

On Friday, all sheets only have 11 "lessons".

FAFRF1F2FBF3F4FFFLFAFO

 

I've used the code below but the index is coming as null.

 

= Table.AddColumn(
#"Changed Type",
"Lesson Index",
each let
Digits = {"0".."9"},
// Split the Lesson column by digits and non-digits
LessonSplit = Splitter.SplitTextByCharacterTransition(each not List.Contains(Digits,_), each List.Contains(Digits,_))([Lesson]),
DayOfWeek = try LessonSplit{0} otherwise null,
NumberPart = try Number.From(LessonSplit{1}) otherwise null,
DayOfWeekIndex = if DayOfWeek = "M" then 0
else if DayOfWeek = "T" then 1
else if DayOfWeek = "W" then 2
else if DayOfWeek = "TH" then 4
else if DayOfWeek = "F" then 5
else null,
// Determine if we are on the first three sheets or the others
ColumnCount = Table.ColumnCount(#"Changed Type"),
SlotIndex = if ColumnCount = 12 then // Sheets with 1 less column (first 3 sheets)
if NumberPart = null then
if [Lesson] = "MA" then 10
else if [Lesson] = "MR" then 20
else if [Lesson] = "M1" then 30
else if [Lesson] = "M2" then 40
else if [Lesson] = "MB" then 50
else if [Lesson] = "M3" then 60
else if [Lesson] = "M4" then 70
else if [Lesson] = "ML" then 80
else if [Lesson] = "M5" then 90
else if [Lesson] = "M6" then 100
else if [Lesson] = "ME" then 110
else if [Lesson] = "MD" then 120
else null
else
DayOfWeekIndex * 100 + NumberPart
else if ColumnCount = 13 then // Sheets with all columns (remaining sheets)
if NumberPart = null then
if [Lesson] = "MA" then 10
else if [Lesson] = "MR" then 20
else if [Lesson] = "M1" then 30
else if [Lesson] = "M2" then 40
else if [Lesson] = "M3" then 50
else if [Lesson] = "MB" then 60
else if [Lesson] = "M4" then 70
else if [Lesson] = "M5" then 80
else if [Lesson] = "ML" then 90
else if [Lesson] = "M6" then 100
else if [Lesson] = "ME" then 110
else if [Lesson] = "MD" then 120
else null
else
DayOfWeekIndex * 100 + NumberPart
else if ColumnCount = 10 then // Fridays with special slots
if NumberPart = null then
if [Lesson] = "FA" then 10
else if [Lesson] = "FR" then 20
else if [Lesson] = "F1" then 30
else if [Lesson] = "F2" then 40
else if [Lesson] = "FB" then 50
else if [Lesson] = "F3" then 60
else if [Lesson] = "F4" then 70
else if [Lesson] = "FF" then 80
else if [Lesson] = "FL" then 90
else if [Lesson] = "FA" then 100
else if [Lesson] = "FO" then 110
else null
else
DayOfWeekIndex * 100 + NumberPart
else null // Fallback for unexpected column counts
in
SlotIndex
)

 

Anyone able to help?

 

Thank you

3 REPLIES 3
danextian
Super User
Super User

Hi @VDS9 

 

What is your expected result? Also, we don't have an access to your raw data.

danextian_0-1738225760672.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

VDS9
Frequent Visitor

Please see file: Sample Report.pbix

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.