Dynamic column names in power bi - powerbi

I have imported an excel file for creating a PBI report. In this excel, there is a cell which contains a date. I want to create columns on the basis of this cell.
Like if the cell contains 01/04/2017 then I would like to generate column names like Apr-17, May-17, ..., Dec-17, Jan-18,..., Mar-18.
If there any way to do this?

I'd say just create a step by step procedure in edit query to pivot the table.
First you'd only get distinct values, then pivot and then promote to headers.

I don't think you need a column per month.
1) Create a query to import your file
2) In Query Editor, select the query, then "Transform" -> "Use First Row As Headers"
3) "Transform" -> "Unpivot Columns"
4) Rename columns as desired
Now you have a table in a comparable/filterable/queryable form. You didn't specify what you need it for but having a column per month won't work well (for various reasons). PowerBi doesn't work quite like excel.
If you really wanted a column per month, you could stop at step 2) but I would advise against it.

Related

Date Hierarchy from calculated column - how?

I have a dashboard to convert - source needs to change from custom, local Excel file to a dataset and SQL Server table via DirectQuery. Excel file was created by exporting data from said dataset, which have been worked over.
Now, the problem is that I don't have date column available, all I can do is convert date_key (int) column into date, and I need a hierarchy to drill down in visuals from years to days.
This is what I have in table based off Excel:
This is what I have in table that I need to use:
Definition of Date:
Date = FORMAT(Date(Left('A'[date_key],4),Right(left('A'[date_key],6),2),right('A'[date_key],2)), "dd/mmmm/yyyy", "en-GB" )
I can create additional columns to add to the hierarchy:
...and it sort of works, but visual is awful to read when drilling down:
instead of
and of course converting month to name (January instead of 1) reorders them alpabetically...
Is there something to be done here, please?

Power BI / Power Query - M language - playing with data inside group table

Hello M language masters!
I have a question about working with grouped rows when the Power Query creates a table with data. But maybe it is better to start from the beginning.
Important information! I will be asking for example only about adding an index. I know that there are different possibilities to reach such a result. But for this question, I need an answer about the possibility to work on tables. I want to use this answer in different actions (e.g table sorting, adding columns in group table).
In my sample data source, I have a list of fake transactions. I want to add an index for each Salesman, to count operations for each of them.
Sample Data
So I just added this file as a data source in Power BI. In Power query, I have grouped rows according to name. This step created form me column contained a table for each Salesman, which stores all his or her operations.
Grouping result
And now, I want to add an index column in each table. I know, that this is possible by adding a new column to the main table, which will be store a new table with added index:
Custom column function
And in each table, I have Indexed. That is good. But I have an extra column now (one with the table without index, and one with a table with index).
Result - a little bit messy
So I want to ask if there is any possibility to add such an index directly to the table in column Operations, without creating the additional column. My approach seems to be a bit messy and I want to find something cleaner. Does anyone know a smart solution for that?
Thank you in advance.
Artur
Sure, you may do it inside Table.Group function:
= Table.Group(Source, {"Salesman"}, {"Operations", each Table.AddIndexColumn(_, "i", 1, 1)})
P.S. To add existing index column to nested table use this code:
= Table.ReplaceValue(PreviousStep,each [index],0,(a,b,c)=>Table.AddColumn(a,"index", each b),{"Operations"})

Is there a formula to automatically drag data form many columns into a new column?

I would like to create a new table in Power Query (for Power BI) with 2 columns that contain data from other columns. These 2 new columns should have the data from the source columns stacked one over eachother. Attached is a link with the desired results.
https://ibb.co/dP1k6pd
What I need is a formula that will automatically update the new columns (ID and cars).
Have not tried anything as I do not have any ideas how to do this yet.
No code provided.
The new columns should automatically drag the data from the source columns and organize it vertically.
Best regards,
Denis
Go to the Edit Queries then select all 3 columns at the header (with shift and mouse click) then go to Transform > Unpivot Columns > Unpivot Only Selected Columns.
You can remove the middle column now and change the column headers to get your desired result.

Delete rows in Power BI

I am new with Power BI and in my dataset I would like to delete some rows. The rows I want to delete have got an ID. However, these indices do not correspond with the row numbers (Row_nr). Basically my data looks like this:
I would like to delete the rows where ID = 7, 14, 16 and 19 (for example, the dataset I use is much bigger) How can I do this in Power BI?
There are several ways to do this. In both cases, edit the data query.
1.) You can filter the data, i.e. select the column filter drop-down, then untick the values you don't want to include.
2.) Or you can create a calculated column with a formula that looks at the ID column and returns a flag, like "keep" or "delete". In the formula you can construct a more complex logic than in the direct filter. The details for that formula will depend on your business logic. Then, in the next step, filter by that helper column and select only "keep". After that you can remove the helper column.

How to add external data as new columns in Power Query?

Today is my first day to use PowerBI 2.0 Desktop.
Is there any way to add new columns from external data into the existing table in my PowerBI?
Or is there anyway to add new columns from another table in PowerBI?
It seems that, in PowerQuery, all the tabs Add Custom Column, Add Index Column and Duplicate Column are all using the existing columns in the same table.....
You can use Merge Queries to join together two queries, which will let you bring in the other table's columns.
Also, Add Custom Column accepts an arbitrary expression, so you can reference other tables in that expression. For example, if Table1 and Table2 had the same number of rows, I could copy over Table2's column by doing the following:
Add an Index Column. Let's call it Index.
Add a Custom Column with the following expression: Table2[ColumnName]{[Index]}