Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
I am a complete newby at Power BI so please excuse the simplicity of this post.
I have a table as follows:
Name | Month | Year | Sales Volume
Joe March 2018 5000
I am trying to measure sales by Month. In addition, I'd like to be able to tabulate quarterly sales, YTD, etc. How do I setup a new column that tabulates the date from the Month and Year columns so that I can use it properly in Power BI? It is end of month data but I do not have the specific end of month dates.
Also, can anyone recommend a good book or website for a beginning user of Power BI that also shows how to properly setup data in Excel to make it easy to analyze?
By the way, I tried to upload the Excel file to this post but was unable to find an attach button. How do I upload files when I submit a question?
Thank you!
Solved! Go to Solution.
Hi,
To compute sales in different time periods, you must use Date and Time Intelligence functions such as SAMEPERIODLASTYEAR(), PREVIOUSMONTH(), DATESYTD() etc. These functions work only when you have an actual date column in your source datasets. So in your Sales data table, you will have to create this calculated column formula to generate a date from the Year and Month
=1*("1/"&Sales[Month]&"/"&Sales[Year])
Format this as a Date and give this column a title, say Date. As a next step, create a Calendar table by using the following formula (Modellling > New Table)
=CALENDAR(MIN(Sales{date]),MAX(Sales{date]))
In the Calendar Table, create addition column for Month and Year by ising these calculated column formulas = YEAR(Calendar[Date]) and =FORMAT(Calendar[Date],"mmmm").
Now create a relatioship from the Date column of the Sales table to the Date column of the Calendar Table. In any visual that you build, drag the year and Month from the Calendar Table. Now you should be able to use measures such as SAMEPERIODLASTYEAR(), PREVIOUSMONTH(), DATESYTD().
Hi,
To compute sales in different time periods, you must use Date and Time Intelligence functions such as SAMEPERIODLASTYEAR(), PREVIOUSMONTH(), DATESYTD() etc. These functions work only when you have an actual date column in your source datasets. So in your Sales data table, you will have to create this calculated column formula to generate a date from the Year and Month
=1*("1/"&Sales[Month]&"/"&Sales[Year])
Format this as a Date and give this column a title, say Date. As a next step, create a Calendar table by using the following formula (Modellling > New Table)
=CALENDAR(MIN(Sales{date]),MAX(Sales{date]))
In the Calendar Table, create addition column for Month and Year by ising these calculated column formulas = YEAR(Calendar[Date]) and =FORMAT(Calendar[Date],"mmmm").
Now create a relatioship from the Date column of the Sales table to the Date column of the Calendar Table. In any visual that you build, drag the year and Month from the Calendar Table. Now you should be able to use measures such as SAMEPERIODLASTYEAR(), PREVIOUSMONTH(), DATESYTD().
Hi Ahish. if you could. pl. help look at this. Just rying to have a better understanding on the basics with the date/time calculations and transformations. Also, is there any resource available online wherein one can try out examples and learn more on analysis involving dates?
br,
//sansk
Hi,
The Date function will defeinitely not work because the second input into that function should be a number (not text). The second one appears correct and should work. Share the link from where i can download your PBI file.
Hi Ashish. Pls. find below the link. Hope this is completely secure.
https://drive.google.com/file/d/1WuDWeh-_W6tuPFcbH96NbbpwWsTvNSJp/view?usp=sharing
Br,
//sansk
Hi,
Try this calculated column formula
Date = 1*("1/"&'date'[Month]&"/"&'date'[Year])
Hope this helps.
Thx. Ashish for your quick help.
If you could pls. help understand the reason for prefix as "1*("
Also , if you could. pls. help with the below expresions - if these will alo fetch the same resuts.
Getting some errors on trying this.
= Date.FromText([Month] & " 1," & Number.ToText([Year]))
= Table.AddColumn(Source, "Custom", each Date.FromText([Month] & " 1," & Number.ToText([Year])))
br,
//sank
Hi,
You are welcome. The 1* converts the "Date formatted as text" into an actual date entry. You may read up on the Date.FromText from here.
Thanks so much for your help. Do you have any suggested reading material or tutorials for someone who is just getting started with Power BI?
Thanks!
You are welcome.
Well, I would create columns like these:
MonthNum = SWITCH([Month],"January",1,"February",2,"March",3) Date = EOMONTH(DATE([Year],[MonthNum],1),0)
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
113 | |
75 | |
75 | |
58 | |
57 |
User | Count |
---|---|
128 | |
109 | |
94 | |
70 | |
68 |