Vintage Chart in Power BI - powerbi

I'm trying to display a vintage analysis line chart in Power BI. I have replicated the chart in Excel from an output of an SQL query.
Each month 0,1,..,12 is the month relative from the business date row representing +1 months from , +2 Months from ... etc.
The issue I'm having is that this dataset doesn't work in Power BI. What does the base data have to look like in order to achieve the line chart as seen in the picture?
The data I have in Power Bi is structured thusly:
[orig] | [0] | 1 | 2 | ... | [12] | [Date]
where orig .. [12] are aggregate columns (counts) for each Date in a cumulative fashion. i.e [n] = Cts + [n-1]. This data is prepared in SQL. Power Bi does no aggregation.
Each date is supposed to be it's own line from 1 - twelve (x axis) with the values being the cumulative totals as described above.
I have made some progress on the chart... looks to be good. except it's backwards...
I have tried creating a sorting column, but get the error message that
FIXED IT!!!!! simple solution. sort ascending on the chart.
But, now, how do I stop PowerBI from displaying a flat line? Below is an example using EXCEL of what the chart should like.

In Power BI the series need to be in columns, so you need to transpose the table and make the dates the column headings. Add a column for the months numbers as text, not numbers, so it can go on the axis.

Try using three columns. One for the date, one for the Category (0,1,2,etc.), and one for the percentage. You can accomplish this by using unpivot in the Power Query window.

Related

How to format a 4 digit year as a date in DAX?

I pulled data into Power BI from a SQL query which returns only the order year in one of the columns. In Power BI I formatted the column as "Data type Date" and "Date time format 2001(yyyy)", but when I pull that column into a table in Power BI, it's clearly calculating 2020 and 2021 as the number of days from 1/1/1900 (like excel) because it shows the year as 1905 for both when inserting this column into a visual, instead of years 2020 and 2021.
How can I format this column as the year 2020 and 2021?
Thank you,
You can convert it in the data source, or you can add a custom column in Power Query with M, or a calculated column in the model with DAX. If your data is not too much, it doesn't really matter where you will do that, but the general recommendation is to do that as close to the data source as you can (i.e. if you can, add it to your query, or if you can't add a calculated column).
The data source option needs a column in your query, which can be added with expression like this (this one uses DATEFROMPARTS T-SQL command, if you are using another database, you will have to change it):
DATEFROMPARTS(ExistingYearOnlyColumn, 1, 1)
Or click Transform data to open Power Query Editor and click Add Column -> Custom Column:
and use #date to create the date:
The last option is to create a calculated column in DAX, by right-clicking on your table and selecting New column:
And use DATE DAX function in an expression like this:
DateColumn = DATE([ExistingYearOnlyColumn], 1, 1)

Column with different data types in Power BI

I would need your support if possible..
Currently within my dataset there is a table "SUM" like below, where columns "Jan" and "Feb" contains both decimal and whole numbers data types.
Is it possible to convert some of the whole number to currency and some other to decimal with 2 decimal places ?
SUM TABLE
title
Jan
Feb
New users
80
90
users
200
150
BV
74562.62
82617.93
Charge
0.063629
0.061740
______________________________________
desired output
title
Jan
Feb
New users
80
90
users
200
150
BV
$745,626
$826,179
Charge
0.06
0.06
______________________________________
I think that in Power BI a column has only one data type.
Is there any way to achieve the desired output?
Thanks in advance
It would be best to structure your data, into a format that it can be used for example, change data types and creating measures.
In this example, using the query editor, you need to first Unpivot your Jan/Feb columns from columns to rows
With unpivot it becomes this:
You then need to Pivot your data on the Title, select the column 'Title' Pivot on the Values column created in the previous step
This now allows you to correct your formatting, create measures, and also map by month better, without the need for complicated DAX formatting when creating measures
To display several data type within a column, you need add new measure for each month you prepare to display and accept the answer if helping :)
Here is the dax formula for Jan, you may need calcuate for Feb if necessary:
Measure = IF(SELECTEDVALUE(Sheet1[title])="BV",FORMAT(SUM(Sheet1[Jan]),"Currency"),
IF(SELECTEDVALUE(Sheet1[title])="Charge",FIXED(SUM(Sheet1[Jan]),2),
FORMAT(SUM(Sheet1[Jan]),"General Number")))
By display the measure on the table, you will have the result:
To display different data types in a table, you can create a measure with the following DAX for the Feb column, you can do the same for other columns too.
Measure =
VAR VAL = SUMMARIZE('Table','Table'[Feb])
RETURN SWITCH( SELECTEDVALUE('Table'[Title]),
"Users", FORMAT(VAL, "0"),
"BV", FORMAT(VAL, "$0"),
"Charge", FORMAT(VAL, "0.00"),
"New Users", FORMAT(VAL , "0")
)

Power BI - Select Slicer Date Between 2 Columns

Hopefully a quick explanation of what I am hoping to accomplish followed by the approach we've been working on for over a year.
Desired Result
I have a table of SCD values with two columns, SCD_Valid_From and SCD_Valid_To. Is there a way to join a date table in my model (or simply use a slicer without a join) in order to be able to choose a specific date that is in between the two SCD columns and have that row of data returned?
Original Table
ID | SCD_Valid_From | SCR_Valid_To | Cost
1 2020-08-01 2020-08-03 5.00
Slicer date chosen is 2020-08-02. I would like this ID=1 record to be returned.
What We've Attempted So Far
We had a consultant come in and help us get Power BI launched last year. His solution was to create an expansion table that would contain a row for every ID/Date combination.
Expanded Original Table
ID | SCD_Valid_Date | Cost
1 2020-08-01 5.00
1 2020-08-02 5.00
1 2020-08-03 5.00
This was happening originally on the Power BI side, and we would use incremental refresh to control how much of this table was getting pushed each day. Long story short, this was extremely inefficient and made the refresh too slow to be effective - for 5 years' worth of data, we would need over 2000 rows per ID just to be able to select a dimensional record.
Is there a way to use a slicer where Power BI can select the records where that selected date falls between dates in two columns of a table?
Let me explain a workaround and I hope this will help you to solve your issue. Let me guess you have below 2 tables-
"Dates" table with column "Date" from where you are generating the date slicer.
"your_main_table" with with column "scd_valid_from" and "scd_valid_to".
Step-1: If you do not have relation between table "Dates" and "your_main_table", this is fine as other wise you have to create a new table like "Dates2". For this work around, you can not have relation between those tables.
In case you have already relation established between those tables, create a new custom table with this below code-
Dates2 =
SELECTCOLUMNS(
Dates,
"Date", Dates[Date]
)
From here, I will consider "Dates2" as source of your Date slicer. But if you have "Date" table with no relation with table "your_main_table", just consider "Dates" in place of "Dates2" in below measures creation. Now, Create these following 4 measures in your table "your_main_table"
1.
date_from_current_row = max(join_using_date_range[SCD_Valid_From])
2.
date_to_current_row = max(join_using_date_range[SCD_Valid_to])
3.
date_selected_in_slicer = SELECTEDVALUE(Dates2[Date])
4.
show_hide_row =
if(
[date_selected_in_slicer] >= [date_from_current_row]
&& [date_selected_in_slicer] <= [date_to_current_row]
,
1,
0
)
Now you have all instruments ready for play. Create your visual using columns from the table "your_main_table"
Final Step: Now just add a visual level filter with the measure "show_hide_row" and set value will show only when "show_hide_row = 1".
The final output will be something like below image-

How to show last six months data(one row for each month) in MDX query based on selected month filter in Power BI report?

I have created a cube with one fact table and 5 dimension which includes one Date dimension. Hierarchy of date dimension is Year -> Quater -> Month. Here I want to select the last six months data from selected month using mdx query. The output should be Month (Row Level) and Measures on Column level.
Thought of creating a dynamic named set but power BI doesn't consume named sets.
Can anyone please suggest a way to do it in MDX either using a disconnected date dimension or any idea in Power BI?
Take a look at the sample below
select
[Measures].[Internet Sales Amount]
on 0
,
[Date].[Calendar].[Month].&[2012]&[4].lag(6):
[Date].[Calendar].[Month].&[2012]&[4]
on 1
from
[Adventure Works]
Result

Date Column in Power BI spiting into 4 columns

I'm using Power BI, pulling data from a SQL server, but for a column containing date, it keeps splitting into 4 other columns when I try and show it in a table:
Year | Quarter | Month | Day
Has anyone had this issue before?
Note: Under modeling, when selecting that field I did try placing Data Type as Date. No change.
This is because Power BI made a date hierarchy from this field. If you do not want this, right click it in the designer and uncheck Date hierarchy from the menu: