cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

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
Super User

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")``

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

Proud to be a Super User!

6 REPLIES 6
Super User

could you pls provide the sample data and expected output

Proud to be a Super User!

Resolver I

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.

"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]``
Super User

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")``

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

Proud to be a Super User!

Resolver I

Thank you @ryan_mayu , that worked.

Super User

you are welcome

Proud to be a Super User!

Helper V

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

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors