Forum Discussion
DAX Question - Interesting
- 2 years ago
PavBidani solution attached, tweak it as you see fit.
- 2 years ago
Hi,
Please find attached the PBI file.
Hope this helps.
To create a bar chart showing fuel produced each year, you can follow these steps using DAX in Power BI or a similar tool:
Data Model Setup: First, ensure that your data is loaded into your data modeling tool (like Power BI) with the necessary columns: DATE, FUEL PRODUCER, FUEL PURCHASER, TOTAL VOLUME, and DURATION OF AGREEMENT.
Create a Calendar Table: If you don't already have a calendar table, create one. This table will help you create a relationship between dates and the contracts. It's essential for time-based calculations.
Define Relationships: Ensure that there's a relationship between the DATE column in your main data table and the date column in the calendar table.
Create a Measure: You'll need to create a DAX measure that calculates the total volume produced each year. Here's an example of how to do that:
Total Volume Per Year =
SUM('YourTableName'[TOTAL VOLUME])
Replace 'YourTableName' with the actual name of your data table.
Create a Bar Chart: Now, create a bar chart visualization. Place the DATE column from your calendar table on the X-axis and the 'Total Volume Per Year' measure on the Y-axis.
Filtering: You can add slicers or filters for FUEL PRODUCER and FUEL PURCHASER to allow users to filter the data based on these criteria if needed.
Your bar chart should now display the fuel produced each year based on your data. The 'Total Volume Per Year' measure calculates the sum of total volume for each year, taking into account any filtering or grouping by FUEL PRODUCER and FUEL PURCHASER.
This setup assumes that you have a calendar table and a proper data model. If you don't have a calendar table, you can create one manually or use DAX functions like CALENDAR to generate one. The key to successful time-based calculations in DAX is having a well-defined date/calendar table and establishing relationships between it and your data tables.