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

Frequent Visitor

## Calculating variance per location

Hi, I'm fairly new to Power BI and DAX. I would very much appreciate the help. Thanks in advance.

I have a database with accidents and incidents, the location where they happened, the month they happened and the reference. I’m trying to calculate the variance in the same way as I do in excel. In excel the grand total is the number of times a location is counted in the data in the current month. A separate tab counts the location listed in the previous month. Variance is then calculated by subtracting the previous month from the current month.

In PowerBI the location is counted by counting the reference (string value) per location. I’ve tried to make measures for the count per location in the current month and the previous month and another measure for the difference (variance). Unfortunately it takes the total and shows that for every location.

Count_reference = COUNT('Data'[Reference])

current month = CALCULATE ([Count_reference], FILTER (ALL ('Data'), 'Data'[Event Month]= DATE (YEAR (TODAY ()), MONTH (TODAY ())-2, 1)))

previous month = CALCULATE ([Count_reference], FILTER (ALL ('Data'), 'Data'[Event Month]= DATE (YEAR (TODAY ()), MONTH (TODAY ())-3, 1)))

monthly variance = [current month]-[previous month]

Is there a way to calculate the variance per location in this specific set of circumstances?

Please find the excel file here:

https://www.dropbox.com/scl/fi/o6928pmqfqahcc1lthc3z/Accidents-and-Incidents-Dummy.xlsx?dl=0&rlkey=6...

1 ACCEPTED SOLUTION
Super User

pls see the attachment below

Proud to be a Super User!

6 REPLIES 6
Super User

which sheet do you want to recreate in PBI?

Proud to be a Super User!

Frequent Visitor

The sheet called "Month Sub Type by Service", specifically column N the Variance prev month

Frequent Visitor

The variance is found in the excel file in the tab called "Month Sub Type by Service" column N.

Super User

pls see the attachment below

Proud to be a Super User!

Frequent Visitor

Amazing, thank you so much!

Super User

you are welcome

Proud to be a Super User!

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