This content originally appeared on DEV Community and was authored by John Kyalo
As a Power BI developer, more than often you'll likely need to track trends over time. It goes without saying that at some point you will be engaging with a calendar.
In DAX, you can easily create a calendar table with all the features of a calendar you need, may it be Quarters in a year or month numbers.
We will explore creating a calendar table :
The first step is specifying the range of dates you want your calendar to contain and you can contain that in variables. You will need to have a calendar that includes the dates present in your calendar
dimCalendar =
VAR Mindate = MIN(Expenditure[Date]
VAR Maxdate = TODAY()
RETURN
ADDCOLUMNS(
CALENDAR(Mindate, Maxdate),
"YEAR" YEAR([Date]),
"MONTH" MONTH([Date]),
"DAY" DAY([Date]),
"MONTHNAME" FORMAT([Date], "MMM"),
"QUARTER", "Q" & QUARTER([Date])
)
The above is a simple calendar that:
- Defines the dates you need in your calendar table as variables
- You need to ADDCOLUMNS to the calendar, and begin by having it said that the calenda will contain the mindate and the maxdate. 3.Specify the columns as needed. Whatever we have in quotation, is the name of the column then returns respective value.
- The format in the Monthname ensure we return our months as 'Jan, Feb' simply as 3 letter words.
- For the Quarter column, the additional Q ensures the name of quarters begin with the prefix Q. This way it adds much more sense.
There you go, try out this simple calendar and use it in your reports.
Anything and Everythind Data!
This content originally appeared on DEV Community and was authored by John Kyalo
John Kyalo | Sciencx (2024-11-12T03:28:38+00:00) Calendar in DAX, Power BI. Retrieved from https://www.scien.cx/2024/11/12/calendar-in-dax-power-bi/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.