I'm tying to compare Azure Cost Management cost to the previous month. The goal is to understand what resources reduce their costs.
I followed this guide that helped me setup PREVIOUSMONTH this way:
PreviousMonth = CALCULATE(
SUM('Usage details'[costInBillingCurrency]),
PREVIOUSMONTH('Usage details'[date].[Date]))
But this formula only returns a blank column.
So I followed this guide that helped me setup this code:
PreviousMonth = CALCULATE(
SUM('Usage details'[costInBillingCurrency]),
PREVIOUSMONTH('Usage details'[date].[Date]),
ALLEXCEPT('Usage details','Usage details'[subscriptionName],'Usage details'[resourceGroupName],'Usage details'[ResourceName] ))
Now values are returned but they are wrong.
So I setup this measure and again the column is empty:
Measure = CALCULATE(
SUM('Usage details'[costInBillingCurrency]),
MONTH('Usage details'[date])=MONTH(TODAY())-1,
YEAR('Usage details'[date])=YEAR(TODAY()))
So how to compare the Azure cost of rescues December VS November?
EDIT: I'm adding new raw data:
Here is the problem:
- the database "preview" exists in October and November but not in December.
- the database "dev" exists only in December
This means that if I select December as a current month I should see dev for the current month but not for the previous month
And in the other hand I should see the preview database for the month of November but an empty space for the month of December.
Ideally I would like to use the color Red/Green for the current month and color in green if the costs is decreased, red if the cost has increased.
You have 2 problems:
To fix it, you need to add a proper calendar table to your model, and then use it for PREVIOUSMONTH. I quickly prototyped it for you to prove:
Your data model should look like this:
You can create the calendar table in many ways - as a calculated table in DAX, in PowerQuery, or import from a database or file. I always prefer to import.
For quick prototyping, you can create a calculated table using DAX code like this:
I added just a couple of fields (year and year-month), but you should create all kinds of fields that are useful for your reports.
Then, connect this new table to table "Data" using date fields. Next, create 2 measures (change names as you please):
and
Notice that I used date from the calendar table, not DATA table.
Finally, I added "Year-Month" field from the calendar table (not from "Data" table) to your visual, to show that it works. If you want to use a slicer, also use date fields from the calendar table.
Power BI is designed to report from a proper dimensional model ( a star schema), with dimensions and fact tables. If you don't build a correct model, you DAX will be complicated and often give wrong results and poor performance.