cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
IHeardPeopleSay Frequent Visitor
Frequent Visitor

Calculated column of distinct months given max week of month

Hi,

Having a table similar to:

Year    Month    WeekOfMonth
2018  1             1
2018  1             2
2018  1             3
2018  2             1
2018  2             2
2018  3             1
2018  3             2
2018  4             1
2018  4             2
2018  4             3
2017  1             1
2017  1             2
2017  2             1
2017  2             2
2017  2             3
2017  3             1
2017  3             2
2017  3             3
2017  4             1
2017  4             2

I want to use a calculated column as a page-level filter to have the following table:

Year    Month    WeekOfMonth
2018  1             1
2018  1             2
2018  1             3
2018  4             1
2018  4             2
2018  4             3

 

That is:

  • Filter the table by the year 2018
  • Of each month, look at the max WeekOfMonth
  • Select only the months with WeekOfMonth = 3

 

This is the formula I have for now:

 

Months5Weeks (2018) =
    VAR M5W =
        CALCULATE(
            DISTINCT(Table[Month]);
            Table[Year] = 2018;
            Table[WeekOfMonth] = 5
        )
    return

    IF(Table[Month] IN {M5W}; Table[Month]; BLANK())

But using that, I only have the following result:

Year    Month    WeekOfMonth
2018  1             3
2018  4             3

 

Which obviously isn't what I'm looking for...

 

Thanks in advance for the help

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: Calculated column of distinct months given max week of month

Hi @IHeardPeopleSay

 

Try this:

1. Place the three fields you show in your first table in the rows of a table visual

2. Create a measure like:

 

ShowMeasure =
VAR _Max =
    CALCULATE ( MAX ( Table1[WeekOfMonth] ), ALL ( Table1[WeekOfMonth] ) )
RETURN
    IF ( _Max = 3, 1 )

 

3. Place [ShowMeasure] in the visual level filters and select to show if it is not blank 

View solution in original post

Super User
Super User

Re: Calculated column of distinct months given max week of month

@IHeardPeopleSay

If you need a column try this:

 

ShowColumn =
VAR _Max =
    CALCULATE ( MAX ( Table1[WeekOfMonth] ), ALL ( Table1[WeekOfMonth] ) )
RETURN
    IF ( _Max = 3 && Table1[Year]= 2018, 1 )

It's pretty much the same since we were using the table visual with all columns already. I've added the 2018 restriction 

View solution in original post

8 REPLIES 8
Super User
Super User

Re: Calculated column of distinct months given max week of month

Hi @IHeardPeopleSay

 

Try this:

1. Place the three fields you show in your first table in the rows of a table visual

2. Create a measure like:

 

ShowMeasure =
VAR _Max =
    CALCULATE ( MAX ( Table1[WeekOfMonth] ), ALL ( Table1[WeekOfMonth] ) )
RETURN
    IF ( _Max = 3, 1 )

 

3. Place [ShowMeasure] in the visual level filters and select to show if it is not blank 

View solution in original post

IHeardPeopleSay Frequent Visitor
Frequent Visitor

Re: Calculated column of distinct months given max week of month

@AlBthanks for the swift reply.

 

I asked for a calculated column because I had to apply it to 45 (sigh) visuals, but if there is no way around it I'll just grit my teeth and do it.

 

That aside, the measure works, but it's clearly not filtered by a specific year, though I'll mark your post as a solution anyway.

Super User
Super User

Re: Calculated column of distinct months given max week of month

@IHeardPeopleSay

If you need a column try this:

 

ShowColumn =
VAR _Max =
    CALCULATE ( MAX ( Table1[WeekOfMonth] ), ALL ( Table1[WeekOfMonth] ) )
RETURN
    IF ( _Max = 3 && Table1[Year]= 2018, 1 )

It's pretty much the same since we were using the table visual with all columns already. I've added the 2018 restriction 

View solution in original post

Super User
Super User

Re: Calculated column of distinct months given max week of month

@IHeardPeopleSay

 

You could also choose to set the restriction on Year = 2018 through a slicer instead of having it hard-coded in the column

IHeardPeopleSay Frequent Visitor
Frequent Visitor

Re: Calculated column of distinct months given max week of month

@AlB

 

I would've used a slicer if the higher entities hadn't said that it's 'ugly.'

 

Though now that I think about it maybe I can just make it invisible.

IHeardPeopleSay Frequent Visitor
Frequent Visitor

Re: Calculated column of distinct months given max week of month

@AlB

 

The ShowColumn formula didn't work, keeps giving the same result I had before:

 

Year    Month    WeekOfMonth
2018  1             3
2018  4             3

 

I'll just use the measure.

Super User
Super User

Re: Calculated column of distinct months given max week of month

@IHeardPeopleSay

 

It should work. Place all three fields, Year, Month and WeekOfMonth, in a table visual and then use the created calculated column in the filters to show when it is not blank.

Otherwise upload the pbix and I'll have a look . We'll make it work 

IHeardPeopleSay Frequent Visitor
Frequent Visitor

Re: Calculated column of distinct months given max week of month

@AlB

 

Strange, it does work today, and can't find what didn't make it work yesterday, most probably a filter I didn't notice.

 

Anyway, thanks for being so forthcoming!

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 282 members 2,924 guests
Please welcome our newest community members: