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

How to Calculate Duration of Matches

Hi Team,
I have a table as shown in below where column "Event" is my expected output. How do I calculted it as a column or Measure.

Event will be based on Year and Week and Non Blank Matches.
Exa- Year 2020 Week 1 - it shows 3 matches - 3 rows. But event will be unique as it happed on continuously for few week.

similarly for 2020 week 4,5,6 ,,,three matches all should be in event 2.

 

Event name should be unique.

 

image.png

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Bhima_Merad 

It hides some complexity, one way of doing so is by adding a column with this:

 

EVENT2 = 
VAR _table1 =
CALCULATETABLE(
    TableName,
    FILTER(
        TableName,
        TableName[Matches]<>BLANK()
    )
)
VAR _table2 =
SUMMARIZE(
    _table1,
    TableName[Year],
    TableName[Week]
)
VAR _table3 =
ADDCOLUMNS(
    _table2,
    "YW",
    TableName[Year]&TableName[Week]
)
VAR _table4=
ADDCOLUMNS(
    _table3,
    "Index",
    RANKX(_table3, [YW], ,ASC)
)
VAR _year = [Year]
VAR _week = [Week]
VAR _value =
MINX(
    FILTER(
        _table4,
        _year = [Year]&&_week = [Week]
    ),
    [Index]
)
RETURN
IF(
    [Matches] = BLANK(),
    BLANK(),
    "Event "&_value
)

 

 

i tried and it worked like this:

FreemanZ_0-1671518134652.png

 

p.s. Rather cumbersome i would say. So please do @ me, if some better solution is proposed. 

View solution in original post

1 REPLY 1
FreemanZ
Super User
Super User

hi @Bhima_Merad 

It hides some complexity, one way of doing so is by adding a column with this:

 

EVENT2 = 
VAR _table1 =
CALCULATETABLE(
    TableName,
    FILTER(
        TableName,
        TableName[Matches]<>BLANK()
    )
)
VAR _table2 =
SUMMARIZE(
    _table1,
    TableName[Year],
    TableName[Week]
)
VAR _table3 =
ADDCOLUMNS(
    _table2,
    "YW",
    TableName[Year]&TableName[Week]
)
VAR _table4=
ADDCOLUMNS(
    _table3,
    "Index",
    RANKX(_table3, [YW], ,ASC)
)
VAR _year = [Year]
VAR _week = [Week]
VAR _value =
MINX(
    FILTER(
        _table4,
        _year = [Year]&&_week = [Week]
    ),
    [Index]
)
RETURN
IF(
    [Matches] = BLANK(),
    BLANK(),
    "Event "&_value
)

 

 

i tried and it worked like this:

FreemanZ_0-1671518134652.png

 

p.s. Rather cumbersome i would say. So please do @ me, if some better solution is proposed. 

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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.