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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Unicorn_Tech
Resolver I
Resolver I

Get # of years, excluding current month

Hello.  I have the following calculated table.  I use "Count of Years" to divide by the sum of page views to get an average for the relevant month. 

I would like the "Count of Years" to exclude the current month, so rather than recording 3 years for Feburary, I would like it to record 2, since we still haven't completed the month.  Is there a way to do that?

 

Avg Rating = Summarize(
    'All Web Site Data','All Web Site Data'[Month Number],
    "Sum per month",
    SUM('All Web Site Data'[Pageviews]),
    "Count of Years", Calculate(DISTINCTCOUNT('All Web Site Data'[Year]))
)

 

1 ACCEPTED SOLUTION

@Unicorn_Tech 

 

i am not sure what's the best solution for this.

 

here is a workaround. maybe you can try to create a column

Column = if(year('Table'[date])=year(today())&&month('Table'[date])=month(today()),"No")

1.png

then filter out the data with "no" value in the visual.





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

Proud to be a Super User!




View solution in original post

6 REPLIES 6
ryan_mayu
Super User
Super User

@Unicorn_Tech 

could you pls provide the sample data and expected output





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

Proud to be a Super User!




Hi @ryan_mayu ,  If you see the table below, the average monthly view here is including Feb. 2023 data, I'd rather it just include 2022 and before, since we still have the month.

Unicorn_Tech_0-1675846106254.png


"Month Number" in my original table is: 

 

Month Number = month('All Web Site Data'[Date])

 

The calculated table is:

Avg Rating = Summarize(
    'All Web Site Data','All Web Site Data'[Month Number],
    "Sum per month",
    SUM('All Web Site Data'[Pageviews]),
    "Count of Years", Calculate(DISTINCTCOUNT('All Web Site Data'[Year]))
)
    

With an "Average Monthly View" column of 

Average Monthly View = 'Avg Rating'[Sum per month] / 'Avg Rating'[Count of Years]

@Unicorn_Tech 

 

i am not sure what's the best solution for this.

 

here is a workaround. maybe you can try to create a column

Column = if(year('Table'[date])=year(today())&&month('Table'[date])=month(today()),"No")

1.png

then filter out the data with "no" value in the visual.





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

Proud to be a Super User!




Thank you @ryan_mayu , that worked.

you are welcome





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

Proud to be a Super User!




Anonymous
Not applicable

Create a measure which is simply month number - 1 and use this in the function instead of month number.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.