Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Off the bat, please forgive me for my ignorance, as I'm just learning Power BI and don't really have any resources close at hand...
I have a table of items that have dates associated to specific items that have been reviewed.
e.g.
Meeting Date
null |
null |
1/24/2019 5:00:00 AM |
null |
null |
8/30/2018 4:00:00 AM |
1/24/2019 5:00:00 AM |
11/30/2018 4:00:00 AM |
9/17/2018 4:00:00 AM |
null |
null |
I perform some activities to convert those dates into YYYY/mm
e.g. 9/17/2018 becomes 2018/9
I then perform a grouping for those new dates and get a new column that shows the sum.
e.g.
2019/01 2
2018/11 1
etc.
I have a calendar table that has YYYY/mm in it which I've related to this table.
I want to display a line graph of the sum of those dates, but, any YYYY/mm with no meetings doesn't show up in the list, and as such, when I display using the calendar table, I get a graph like this...
When I group the column values, how do I make sure that if there isn't a value for a particular month that it still has a 0 so it appears in the graph?
Solved! Go to Solution.
To create a Measure, you click "New Measure" on the "Modeling" tab:
The following will show up in the formula bar:
Replace the selected text with the formula stated earlier, but you will need to replace "Your Table'[Your Column] with the table/column you're currently using for the line in your chart.
Change your chart, so that "Line Values" is based on this new measure, instead of the original column.
Hope this helps,
Nathan
@zenmonkey - You can create a new Measure that does something like the following:
My Count = COUNTROWS('Your Table') + 0
Adding the zero turns it from a blank to a zero.
I understand what you're doing, but I have no idea where to implement. I'm guessing I'm doing something wrong with the data in my query, but I'm not certain how to do it differently.
After manipulating the date info to go from mm/d/yyyy to yyyy/mm, and performing a number of other steps,
I obtained the list of dates (YYYY/mm) and their count by using the "Grouped Rows" step in the Query Editor (see query output below). Since there is no data in this final table for 2018/09, I assume I need to do something different to ensure that every month is accounted for.
YYYY/mm | # Reviewed |
null | 48 |
2018/08 | 5 |
2018/10 | 3 |
2018/11 | 8 |
2018/12 | 6 |
2019/01 | 13 |
2019/02 | 1 |
2019/03 | 19 |
2019/04 | 37 |
For YTD to work properly, you need to have a column of Date datatype for individual dates, either in a separate Date table, or through the Date table that gets created automatically in the background. In your case, since you want to use a Year/Month column, you will want to add that to your Date table. An example Date Power Query M script is below.
You will need to create a relationship between your Fact table and the Date table. If the fact table contains monthly, instead of daily data, the relationship will need to be many-to-many.
Finally, use the Year/Month column from the Date table in your visual, and YTD should work correctly.
Date table script:
let //Set the following variables Culture = "English (United States)", //Select a culture. UseYesterdayAsCurrentDate = true, //true = yesterday, false = today YearsBack = 2, //How many years to include prior to the current year. YearsAhead = 2, //How many years to include after the current year. GoToBeginning = "Year", //Options: Year, Month, None GoToEnd = "Year", //Options: Year, Month, None //Figure the Start and End Dates, based on above variables DateToday = DateTime.Date(DateTime.LocalNow()), CurrentDate = if UseYesterdayAsCurrentDate = true then Date.AddDays(DateToday, -1) else DateToday, YearBegin = Date.Year(CurrentDate) - YearsBack, MonthBegin = if GoToBeginning = "Year" then 1 else Date.Month(CurrentDate), DayBegin = if GoToBeginning = "None" then Date.Day(CurrentDate) else 1, StartDate = #date(YearBegin, MonthBegin, DayBegin), YearEnd = Date.Year(CurrentDate) + YearsAhead, MonthEnd = if GoToEnd = "Year" then 12 else Date.Month(CurrentDate), DayEndTemp = if GoToEnd = "Year" then 31 else Date.Day(CurrentDate), EndDateTemp = #date(YearEnd, MonthEnd, DayEndTemp), EndDate = if GoToEnd = "Month" then DateTime.Date(Date.EndOfMonth(EndDateTemp)) else EndDateTemp, DayCount = Duration.Days(Duration.From(EndDate - StartDate)) + 1, //Get complete list of dates, Convert to a table, update name and data type AllDates = List.Dates(StartDate,DayCount,#duration(1,0,0,0)), TableFromList = Table.FromList(AllDates, Splitter.SplitByNothing()), ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}), RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Date"}}), //Add other attributes of the date, as desired InsertYear = Table.AddColumn(RenamedColumns, "Year", each Date.Year([Date])), InsertQuarterOfYear = Table.AddColumn(InsertYear, "Quarter Of Year", each Date.QuarterOfYear([Date])), InsertMonthOfYear = Table.AddColumn(InsertQuarterOfYear, "Month Of Year", each Date.Month([Date])), InsertDayOfMonth = Table.AddColumn(InsertMonthOfYear, "Day Of Month", each Date.Day([Date])), InsertDayOfWeek = Table.AddColumn(InsertDayOfMonth, "Day Of Week", each Date.DayOfWeek([Date])), InsertDateAlternateKey = Table.AddColumn(InsertDayOfWeek, "Date Alternate Key", each [Year] * 10000 + [Month Of Year] * 100 + [Day Of Month]), InsertMonthName = Table.AddColumn(InsertDateAlternateKey, "Month Name", each Date.ToText([Date], "MMMM", Culture), type text), InsertMonthKey = Table.AddColumn(InsertMonthName, "Month Key", each [Year] * 100 + [Month Of Year]), InsertMonthYear = Table.AddColumn(InsertMonthKey, "Month Year", each (try(Text.Range([Month Name],0,3)) otherwise [Month Name]) & " " & Number.ToText([Year])), InsertQuarterName = Table.AddColumn(InsertMonthYear, "Quarter Name", each "Q" & Number.ToText([Quarter Of Year])), InsertQuarterKey = Table.AddColumn(InsertQuarterName, "Quarter Key", each [Year] * 100 + [Quarter Of Year]), InsertQuarterYear = Table.AddColumn(InsertQuarterKey, "Quarter Year", each "Q" & Number.ToText([Quarter Of Year]) & " " & Number.ToText([Year])), InsertDayName = Table.AddColumn(InsertQuarterYear, "Day Of Week Name", each Date.ToText([Date], "dddd", Culture), type text), InsertWeekEnding = Table.AddColumn(InsertDayName, "Week Ending", each Date.EndOfWeek([Date]), type date), //Add Relative Date Positions. InsertRelativeYear = Table.AddColumn(InsertWeekEnding, "Relative Year", each [Year]-Date.Year(CurrentDate)), InsertRelativeYearDescription = Table.AddColumn(InsertRelativeYear, "Relative Year Description", each if [Relative Year] = 0 then "Current Year" else if [Relative Year] = -1 then "Last Year" else if [Relative Year] = 1 then "Next Year" else if [Relative Year] < -1 then Number.ToText(Number.Abs([Relative Year])) & " Years Back" else Number.ToText([Relative Year]) & " Years Ahead"), InsertRelativeQuarter = Table.AddColumn(InsertRelativeYearDescription, "Relative Quarter", each 4*([Year]-Date.Year(CurrentDate)) + ([Quarter Of Year]-Date.QuarterOfYear(CurrentDate))), InsertRelativeQuarterDescription = Table.AddColumn(InsertRelativeQuarter, "Relative Quarter Description", each if [Relative Quarter] = 0 then "Current Quarter" else if [Relative Quarter] = -1 then "Last Quarter" else if [Relative Quarter] = 1 then "Next Quarter" else if [Relative Quarter] < -1 then Number.ToText(Number.Abs([Relative Quarter])) & " Quarters Back" else Number.ToText([Relative Quarter]) & " Quarters Ahead"), InsertRelativeMonth = Table.AddColumn(InsertRelativeQuarterDescription, "Relative Month", each 12*([Year]-Date.Year(CurrentDate)) + ([Month Of Year]-Date.Month(CurrentDate))), InsertRelativeMonthDescription = Table.AddColumn(InsertRelativeMonth, "Relative Month Description", each if [Relative Month] = 0 then "Current Month" else if [Relative Month] = -1 then "Last Month" else if [Relative Month] = 1 then "Next Month" else if [Relative Month] < -1 then Number.ToText(Number.Abs([Relative Month])) & " Months Back" else Number.ToText([Relative Month]) & " Months Ahead"), InsertRelativeWeek = Table.AddColumn(InsertRelativeMonthDescription, "Relative Week", each Duration.Days(Duration.From([Week Ending]-Date.EndOfWeek(CurrentDate)))/7), InsertRelativeWeekDescription = Table.AddColumn(InsertRelativeWeek, "Relative Week Description", each if [Relative Week] = 0 then "Current Week" else if [Relative Week] = -1 then "Last Week" else if [Relative Week] = 1 then "Next Week" else if [Relative Week] < -1 then Number.ToText(Number.Abs([Relative Week])) & " Weeks Back" else Number.ToText([Relative Week]) & " Weeks Ahead"), InsertRelativeDay = Table.AddColumn(InsertRelativeWeekDescription, "Relative Day", each Duration.Days(Duration.From([Date]-CurrentDate))), InsertRelativeDayDescription = Table.AddColumn(InsertRelativeDay, "Relative Day Description", each if [Relative Day] = 0 then "Current Day" else if [Relative Day] = -1 then "Last Day" else if [Relative Day] = 1 then "Next Day" else if [Relative Day] < -1 then Number.ToText(Number.Abs([Relative Day])) & " Days Back" else Number.ToText([Relative Day]) & " Days Ahead"), //Add Date Category Positions. InsertYearGroup = Table.AddColumn(InsertRelativeDayDescription, "Year Group", each if [Relative Year] = 0 then "Current Year" else if [Relative Year] < 0 then "Past Years" else "Future Years"), InsertQuarterGroup = Table.AddColumn(InsertYearGroup, "Quarter Group", each if [Relative Quarter] = 0 then "Current Quarter" else if [Relative Quarter] < 0 then "Past Quarters" else "Future Quarters"), InsertMonthGroup = Table.AddColumn(InsertQuarterGroup, "Month Group", each if [Relative Month] = 0 then "Current Month" else if [Relative Month] < 0 then "Past Months" else "Future Months"), InsertWeekGroup = Table.AddColumn(InsertMonthGroup, "Week Group", each if [Relative Week] = 0 then "Current Week" else if [Relative Week] < 0 then "Past Weeks" else "Future Weeks"), InsertDayGroup = Table.AddColumn(InsertWeekGroup, "Day Group", each if [Relative Day] = 0 then "Current Day" else if [Relative Day] < 0 then "Past Days" else "Future Days"), #"Changed Type" = Table.TransformColumnTypes(InsertDayGroup,{{"Year", Int64.Type}, {"Quarter Of Year", Int64.Type}, {"Month Of Year", Int64.Type}, {"Day Of Month", Int64.Type}, {"Day Of Week", Int64.Type}, {"Date Alternate Key", Int64.Type}, {"Quarter Name", type text}, {"Month Year", type text}, {"Quarter Year", type text}, {"Relative Year Description", type text}, {"Relative Quarter Description", type text}, {"Relative Month Description", type text}, {"Relative Week Description", type text}, {"Relative Day Description", type text}, {"Year Group", type text}, {"Quarter Group", type text}, {"Month Group", type text}, {"Week Group", type text}, {"Day Group", type text}, {"Relative Day", Int64.Type}, {"Relative Week", Int64.Type}, {"Relative Month", Int64.Type}, {"Relative Quarter", Int64.Type}, {"Relative Year", Int64.Type}, {"Quarter Key", Int64.Type}, {"Month Key", Int64.Type}}), //Add Date In Fact Table Attributes. maxSales = Date.AddDays(DateToday, -1), //List.Max(Table.Column(Sales, "SalesDate")), // InsertHasSalesData = Table.AddColumn(#"Changed Type", "Has Sales Data", each if [Date] <= maxSales then "Yes" else "No"), InsertHasSalesDataCompleteMonth = Table.AddColumn(InsertHasSalesData, "Has Sales Data Complete Month", each if Date.EndOfMonth([Date]) <= maxSales then "Yes" else "No") in InsertHasSalesDataCompleteMonth
Again, I am extremely grateful for your help!!!
I already have a date table and it is related to the fact table. The date table has a YYYY/mm column that I am using in a many to many relationship with "Both" for the cross filter direction linked to the derived YYYY/mm column in the fact table.
The YYYY/mm column from the date table is the shared axis for the graph that I included in the original message in this thread.
The issue is that the line in the line & bar graph doesn't have data for all of the months, (e.g. 2018/09) and as such the line is broken rather than showing zero. Your suggestion of adding "+0" would solve the problem, but again, I don't know where to do it.
I also wonder if I'm transforming the data incorrectly with my query
@zenmonkey - Ah, currently your line graph must be based on a field, you can add a new Measured, and use it for the line. It could be:
Line Measure = SUM('Your Table'[Your Column]) + 0
OK. we're almost back where we started... I don't know how to implement what you're suggesting.
To create a Measure, you click "New Measure" on the "Modeling" tab:
The following will show up in the formula bar:
Replace the selected text with the formula stated earlier, but you will need to replace "Your Table'[Your Column] with the table/column you're currently using for the line in your chart.
Change your chart, so that "Line Values" is based on this new measure, instead of the original column.
Hope this helps,
Nathan
Thank you for the walk through!
I understand what you're saying, but I don't know how to implement it. I wonder if I'm doing things correctly with my query.
Here's the process (applied steps) that I've done to the data.
1) Source (Select Sharepoint site)
2) Navigation (select specific sharepoint list)
3) Removed other Columns. (Remove all other columns except "Meeting Date")
Meeting Date
null
null
8/30/2018 4:00:00 AM
null
1/24/2019 5:00:00 AM
null
...
4) Addded Custom (Custom column formula to get the month: "=Date.Month([Meeting Date])" )
Month
null
null
8
null
1
null
...
5) Addded Custom (Custom column formula to get the year: "=Date.Year([Meeting Date])" )
Year
null
null
2018
null
2019
null
...
6) Addded Custom (Custom column formula to convert month to 2 digits: "=Text.PadStart(Text.From([Month]),2,"0")" )
2DigiMonth
null
null
08
null
01
null
...
7) Addded Custom (Custom column formula to get YYYY/mm: "=Text.From([Year]) & "/" & Text.PadStart(Text.From([Month]),2,"0")" )
YYYY/mm
null
null
2018/08
null
2019/01
null
...
😎 Grouped Rows (w/Count Rows)
null 68
2018/08 1
2019/01 1
...
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
84 | |
75 | |
68 | |
41 | |
35 |
User | Count |
---|---|
102 | |
56 | |
52 | |
46 | |
40 |