I have a table with places and corresponding population per year. Currently I only have data up to year 2018. Somethin like this:
+-------+------+------------+
| Place | Year | Population |
+-------+------+------------+
| a | 2017 | 12 |
| a | 2018 | 11 |
| b | 2017 | 43 |
| b | 2018 | 21 |
+-------+------+------------+
I've created a measure that sums the "Population" column values and used it in a columns chart with the "Year" column as the axis to see the total population per year. The data in the chart would be:
+------+-------+
| Year | Total |
+------+-------+
| 2017 | 55 |
| 2018 | 33 |
+------+-------+
I need the chart to also show years 2019 and 2020 with the same value from 2020, like:
+------+-------+
| Year | Total |
+------+-------+
| 2017 | 55 |
| 2018 | 33 |
| 2019 | 33 |
| 2020 | 33 |
+------+-------+
How can I achieve the above via DAX. I basically need to take the "Total" from the MAX "Year" and dynamically create two additional entries for 2019 and 2020 with the same total from that MAX "Year".
My use case is more involved as then I will have to add another measure to the same columns chart to show how many of that total population attended a particular class. My table with the "class attendance" data does have values up to 2020 which is why I need the total population to go all the way to 2020 and assume that the population for 2019 and 2020 is the same than in 2018 so then I can compare that with class attendance numbers.
Any help or guidance is welcomed.
Thanks.
This can be achieved very easily by power query: (may be there will be a way to do it in measures as well)
Assuming you data would be something like this:
You can go to Transform tab and perform group by like below
Now Select the Fill(Down) in the Transform tab like below
Finally you can in the visualization tab you can create below:
Related
I want to make a query to count borrowing report every month . But i'd saved my data in unixtime.
tablename:borrow
attributes:borrowingID,dateOfBorrow,dateOfReturn,statusBook
For example the dateOfBorrow is 167077440 and i just want to count the specific month for jan,feb,etc..
i am expecting
| Month | Total |
| ------| ----- |
| Jan | 2 |
| Feb | 5 |
| Mar | 5 |
...etc
select from_unixtime(167077440),from_unixtime(167077440,'%b')
+--------------------------+-------------------------------+
| from_unixtime(167077440) | from_unixtime(167077440,'%b') |
+--------------------------+-------------------------------+
| 1975-04-18 19:24:00 | Apr |
+--------------------------+-------------------------------+
1 row in set (0.001 sec)
See manual https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_from-unixtime and https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format
But are you really interested in 1975?
I have data showing me the dates grouped like this:
For security reasons, I had to remove the Customer Description detail, due to confidentiality.
How do I repeat the date column the same way you repeat the Row Labels in an Excel Pivot?
I've looked, but couldn't find a solution to this - this option should be available.
EDIT
When you have the following source data in Excel:
Date | Customer | Item Description | Qty Out | Unit Price | Sales
--------------------------------------------------------------------------------------------------------------------------------------------
14/08/2020 | Customer 1 | Item 11 | 4.00 | 65.00 | 260.00
14/08/2020 | Customer 2 | Item 12 | 56.00 | 12.00 | 672.00
14/08/2020 | Customer 3 | Item 13 | 64.00 | 35.00 | 2,240.00
14/08/2020 | Customer 4 | Item 14 | 29.00 | 65.00 | 1,885.00
15/08/2020 | Customer 2 | Item 15 | 746.00 | 12.00 | 8,952.00
15/08/2020 | Customer 3 | Item 16 | 14.00 | 75.00 | 1,050.00
15/08/2020 | Customer 4 | Item 17 | 45.00 | 741.00 | 33,345.00
15/08/2020 | Customer 5 | Item 18 | 456.00 | 125.00 | 57,000.00
15/08/2020 | Customer 6 | Item 19 | 925.00 | 17.00 | 15,725.00
16/08/2020 | Customer 4 | Item 20 | 6.00 | 532.00 | 3,192.00
16/08/2020 | Customer 5 | Item 21 | 56.00 | 94.00 | 5,264.00
16/08/2020 | Customer 6 | Item 22 | 546.00 | 37.00 | 20,202.00
You then pivot this data using Microsoft Excel, where you get the following:
You then choose the option to Repeat Item Labels as can be seen below:
After selecting this, you get my expected results I require in Power BI:
Is there not a function available like this in Power BI?
Just adding this for your reference as a work around. Check this below image with a custom column created in the Power Query Editor-
date_customer = Date.ToText([Date]) &" : "& [Customer]
Then added both Date and date_customer in the Matrix row level. The output is as below- (using your sample data)
ANOTHER OPTION Another option is to add Date and Customer in the Matrix row and the output is will be as below- (using your sample data)
This is also a meaningful output as date are showing as a group header. But in case of requirement of having redundant date to show, you can consider the first option.
yet another Power BI problem I'm having that I've tried to solve to no avail..
I'm trying to create a calculated column to flag if a record is in this year.
I have a planning table:
FiscalYear | ReportDate | Status |
2017 | 01/4/2018 | Open |
2018 | | Open |
2017 | | Closed |
2016 | 01/10/2016 | Complete |
2016 | 01/8/2017 | Complete |
I have a measure [Current Year] that returns 2018/19 as text.
I have a date table with every date, sample below of selected years:
FiscalYear | FiscalYearSlash| Date |
2017 | 2017/18 | ..........|
2018 | 2018/19 | ..........|
2017 | 2017/18 | ..........|
2016 | 2016/17 | ..........|
2016 | 2016/17 | ..........|
I can return FiscalYearSlash in the planning table with:
CALCULATE(VALUES(Dates[FiscalYearSlash]),
FILTER(Dates,
Dates[FiscalYear]=Planning[FiscalYear]))
but when I put this as the condition in an IF statement, it comes out false every time. Both the column and the measure are text. Any ideas?
Wondering if it's something to do with context transition. I've watched some of the SQLBI.com videos and understand them but when it comes to applying it.. struggling a bit. Thanks.
Here's the IF statement I'm trying:
IF( CALCULATE(VALUES(Dates[FiscalYearSlash]),
FILTER(Dates,
Dates[FiscalYear]=Planning[FiscalYear]))
= CurrentYear,"yes","no")
I've solved this. I returned the current year as a VAR in the function, as opposed to a measure:
VAR CurrentYear = CALCULATE(VALUES(Dates[FiscalYearSlash]),
FILTER(Dates,Dates[Date]=TODAY()))
RETURN
SWITCH(TRUE(),
CALCULATE(VALUES(Dates[FiscalYearSlash]),
FILTER(Dates,
Dates[FiscalYear]=Planning[FiscalYear]))=CurrentYear,
"Yes","No"
)
I have a Matrix visual in Microsoft PowerBI with Australian 'States' as rows and 'Months Ago' as columns.
By default the Matrix shows my columns from 0 months ago to 12. I would like it to show from 12 months ago on the left to 0 months ago on the right.
+-------------------+-----------------------------+-------+
| | Months Ago | |
+-------------------+-----------------------------+-------+
| State | 0 | 1 | 2 | 3 | 4 | 5 | Total |
+-------------------+----+----+----+----+----+----+-------+
| Queensland | 10 | 10 | 10 | 10 | 10 | 10 | 60 |
+-------------------+----+----+----+----+----+----+-------+
| New South Wales | | | | | | | |
+-------------------+----+----+----+----+----+----+-------+
| Victoria | | | | | | | |
+-------------------+----+----+----+----+----+----+-------+
| South Australia | | | | | | | |
+-------------------+----+----+----+----+----+----+-------+
| Western Australia | | | | | | | |
+-------------------+----+----+----+----+----+----+-------+
Currently I am only given the option to sort by the value type fields (ie revenue etc).
Is there any option to sort/order the Column Headers?
I don't think there is an option for you to sort column headers directly.
However, you can change the default sort order for the Months Ago column so that it will be reflected in general.
You can add a custom column MonthSrt = 12 - [Months Ago] in query editor:
(It won't work in DAX because of a known issue)
Then you can select the Months Ago column and sort it by MonthSrt:
The custom sort will be applied when you use the Months Ago column in visuals:
You can also make groups (1 to 1 items) al give them al logical number:
The order will change automaticly in the matrix
The following solution worked for me to display the dates in descending order in a matrix:
how to sort column dates in descending order of matrix in power bi
I'm currently using the following code to display a text with a Long Text Viewer when the user selects a Country from the slicer:
Notes =
IF(
HASONEFILTER(Data[Country]),
CONCATENATEX(Data, Data[Comments], "\n\n"),
"Please select only one Country from the list."
)
However, I've now separated [Comments] from the Data dataset into another dataset called Comment. I'm not sure how the relationships quite work but I checked the Manage Relationships dialog box and a 1:M relationship is active between the Data and Comment datasets.
This is how both datasets look like:
> Data dataset
Month | Year | Region | Prod % | ...
Jan | 2016 | NAM | 80% | ...
Jan | 2016 | LAM | 40 | ...
Jan | 2016 | EUR | 60% | ...
Jan | 2016 | AFR | 70% | ...
Jan | 2016 | SEA | 80% | ...
Jan | 2016 | GCN | 70% | ...
> Comment dataset
Month | Year | Region | Comments
Jan | 2016 | NAM | Jan NAM comment here
Jan | 2016 | LAM | Jan LAM comment here
Jan | 2016 | EUR | Jan EUR comment here
Jan | 2016 | AFR | Jan AFR comment here
Jan | 2016 | SEA | Jan SEA comment here
Jan | 2016 | GCN | Jan GCN comment here
Is it possible that when the user selects a [Month], [Year] and [Region] from the Data dataset, it would display the appropriate [Comments] from the Comment dataset? Also, I'm not sure on how Primary Keys work in Power BI (both datasets don't have any Primary Keys).
Edit: So I tried this formula after merging the Comment dataset with the Data dataset:
Notes =
IF(
HASONEFILTER(Data[Region]) && HASONEFILTER(Data[Year]) && HASONEFILTER(Data[Month]),
CONCATENATEX(Data, Data[Comment.Comment], "\n\n"),
"Please select only one Period and Region from the list"
)
However, it is displaying the comment multiple times (there were 4 countries selected in the dataset. Would it be possible to make it display the [Comment] that is unique to that [Month], [Year] and [Region]?
I would add a VALUES function to your CONCATENATEX function to summarize the Comments, e.g.
CONCATENATEX( VALUES ( Data[Comment.Comment] ) , Data[Comment.Comment], "\n\n")