Is there a way I can reorder columns in 'Data View' within Power BI? I tried doing it in Power Query first but when the data loads into the table, the columns automatically rearrange.
Edit after comment.
There is easy fix to enforce column order just as in Power Query:
In Power Query Editor > Disable Query Load. Close and Apply.
Open the Query Editor again, enable the Query Load. Refresh the Query. Then Close and Apply.
Answer to misunderstood question.
This may be interesting solution in M PowerQuery. The function below let you reorder columns by only stating few columns from the whole set of columns. Add this in blank query and rename it to FnReorderColumnsSubset.
(tbl as table, reorderedColumns as list, offset as number) as table =>
Table.ReorderColumns
(
tbl,
List.InsertRange
(
List.Difference
(
Table.ColumnNames(tbl),
reorderedColumns
),
offset,
reorderedColumns
)
)
Use it as this:
= FnReorderColumnsSubset( Source, { "Region", "RegionManager", "HeadCount" }, 0 )
Found it here:
https://datachant.com/2017/01/18/power-bi-pitfall-4/
It is extremely stupid way, but it is working - i found it by accident:
In edit query view remove the column, then save changes. You will see that in data view that column was removed as well.
Now again in edit query view remove from applied steps the action that removed the column. Save it again.
You will see that removed previously column was added to the end of the table.
This way you can arrange your columns to have it the way you want it in data view.
Hope it helped.
I don't know that you can rearrange an existing table, but if you re-create it as a new table, you can pick the order you want.
NewTable =
SELECTCOLUMNS (
OldTable,
"Column1", OldTable[Column1],
"Column2", OldTable[Column2],
"Column3", OldTable[Column3]
)
I think most here have misunderstood the problem, except #Jacko. So far as I know it is now possible to re-arrange columns in Power Query and load to the model and the table will load in the column order you specified in PQ. The problem is in dataview in the modelling layer of PBi. Here you can add many calculated columns, but, any new column you add is always placed at far right and can't be moved. Yes, I know about SELECTCOLUMNS but it isn't a solution as the new table does not have the editable formulae. A solution is a drag and drop feature of some sort. PBi users are still waiting for it despite the problem being flagged in MS Forums some years ago. No progress TIKO other than the limp SELECTCOLUMNS solution.
Related
In Power BI, I need to create a VLOOKUP alternative. From the research I've done, this is done with the LOOKUPVALUE function, but the problem is that function needs one specific SEARCH ITEM, which isn't super helpful in a VLOOKUP type scenario where you have a full column of values to search for?
Given these two tables, connected through the user_name and first_name columns:
...what's the formula needed in order to create a new column in the Employee_Table called phone_call_group by using the names as the search items in order to return the group they belong to? So how can I end up with this?
(Forget that the entries in each table are already sorted, needs to be dynamic). Will be back tomorrow to review solutions.
In Power BI you have relations between tables instead of Excel's VLOOKUP function.
In your case you just have to create a one-to-one relation between
'Phone_Call_Table'[user_name] and 'Employee_Table'['first_name]'
With that you can add a Calculated Column to your 'Employee_Table' using the following expression:
phone_call_group = RELATED(Phone_Call_Table[group])
and in the data view the table will look like this:
LOOKUPVALUE() is just a workaround if for other reasons you can't establish that relation. What you've been missing so far is that in a Calculated Column there is a Row Context which gives you exactly one value per row for the <search_value> (this is different from Measures):
alt_phone_call_group =
LOOKUPVALUE(
Phone_Call_Table[group],
Phone_Call_Table[user_name],
Employee_Table[first_name]
)
I have a table with two choices 'FLOW_CONTEXT' and 'TEST_NAME'.
I want to let the user select one of these values using a slicer. I then want to have a calculated formula point to either the 'FLOW_CONTEXT' or the 'TEST_NAME' column in another table. There is a 1:1 relationship between the 'FLOW_CONTEXT' and the 'TEST_NAME' columns in the table.
Here is the column formula I have, which always defaults to false, even though the SELECTEDVALUE part of the IF statement does work (checked via a card):
COLUMN_POINTER = IF(
SELECTEDVALUE(TEST_NAME_FIELD[TEST_NAME_FIELD]) = "FLOW_CONTEXT",
CCD_BINNING_TEST_RESULTS_LAST_RANK[FLOW_CONTEXT],
CCD_BINNING_TEST_RESULTS_LAST_RANK[TEST_NAME]
)
I have tried doing this with a measure but measures only see non-categorical columns. Thx much.
Columns are only calculated at refresh time - they do not respond to slicers filters in this way. You cannot re-calculate a column based on a selected value in a table visual.
You need to transform your use-case into a measure-friendly approach.
I have a table Deals which has columns [DealId], [Open Date Id], [Closed Date Id] where the last 2 columns are like a foreign key to the Date table which has [Date], [DateId] column.
Power BI won't let me have 2 active relationship, so one is inactive.
Now I want to create some visuals indicating the deals that were open and closed in a custom range of time (using slicer).
How I tried to solve
The closest solution to this was creating a calculated column with the LOOKUPVALUE and adding the close and open dates directly to Deals table. And created 2 different pages with 2 different slicers, but this is far not the solution I wanted.
How can I solve this problem?
I don't know if what I'm going to say suits your needs based on the size of the tables or the rigidity of the data model due to other measures. I think that in the end what matters is to understand what are the limitations of what you want to show. However, something almost similar I answered here: https://stackoverflow.com/a/66792957/15460989
From what I could understand you have two tables similar to:
Deals = {[DealID] [OpenDate] [CloseDate] [Quantity] [Price] ...}
Dates = {[Date] [MonthName] [MonthNumber] [Year] ...}
And you want to filter Deals based on two relationships
USERELATIONSHIP (Dates [Date], Deals [OpenDate])
USERELATIONSHIP (Dates [Date], Deals [CloseDate])
I am not going to discuss the option of duplicating Dates Table because it was previously covered using two slicers.
But what if the characteristics of my model allow me to use a table with two relationship (One active and the other inactive) while my visualization uses the content of an unrelated table?
Let's define my new unrelated table as:
HarvestingDates = {[Date] [MonthName] [MonthNumber] [Year] ...}
and what I'm trying to achieve is something like this:
From a model like this one:
Deals[DealID]: Unique values.
Deals[OpenDate]: Repeated and missing dates
Deals[CloseDate]: A random number between 0 and 5 is added to Deals [OpenDate]
Instead of choosing an opening date and a closing date, I choose a date range not related to the model and the context related to the deals comes from the measures. Example:
Opened Deals: All the deals opened in a certain date range and summarized by the visualization.
HOpenedDeals: =
CALCULATE(
COUNTROWS(Deals),
TREATAS(
VALUES(HarvestingDate[Date]),Dates[Date]
)
)
Closed Deals: All the deals closed in a certain date range and summarized by the visualization.
HClosedDeals:=
CALCULATE(
COUNTROWS(Deals),
USERELATIONSHIP(Dates[Date],Deals[CloseDate]),
TREATAS(VALUES(HarvestingDate[Date]),Dates[Date])
)
Open and closed deals: All open and closed deals in the same date range summarized by the visualization
HOpened&Closed :=
VAR TotalRow= SUMMARIZE(HarvestingDate,HarvestingDate[Year],HarvestingDate[MonthName])
VAR CurrentDates=VALUES(HarvestingDate[Date])
VAR Result=
ADDCOLUMNS(TotalRow, "Count",
VAR CurrentMonthName= {CALCULATE(VALUES(HarvestingDate[MonthName]))}
VAR CurrentYear= {CALCULATE(VALUES(HarvestingDate[Year]))}
RETURN
COUNTROWS(INTERSECT(
CALCULATETABLE(Deals,
USERELATIONSHIP(Dates[Date],Deals[CloseDate]),
TREATAS(CurrentMonthName, Dates[MonthName]),
TREATAS(CurrentYear, Dates[Year]),
TREATAS(CurrentDates, Dates[Date])
),
CALCULATETABLE(Deals,
TREATAS(CurrentMonthName, Dates[MonthName]),
TREATAS(CurrentYear, Dates[Year]),
TREATAS(CurrentDates, Dates[Date])
)
)))
RETURN SUMX(Result,[Count])
Opened & Not Closed Deals: All open and non-closed deals in the same date range summarized by visualization
HO&NOTC :=
VAR TotalRow= SUMMARIZE(HarvestingDate,HarvestingDate[Year],HarvestingDate[MonthName])
VAR CurrentDates=VALUES(HarvestingDate[Date])
VAR Result=
ADDCOLUMNS(TotalRow, "Count",
VAR CurrentMonthName= {CALCULATE(VALUES(HarvestingDate[MonthName]))}
VAR CurrentYear= {CALCULATE(VALUES(HarvestingDate[Year]))}
RETURN
COUNTROWS(EXCEPT(
CALCULATETABLE(Deals,
TREATAS(CurrentMonthName, Dates[MonthName]),
TREATAS(CurrentYear, Dates[Year]),
TREATAS(CurrentDates, Dates[Date])
),
CALCULATETABLE(Deals,
USERELATIONSHIP(Dates[Date],Deals[CloseDate]),
TREATAS(CurrentMonthName, Dates[MonthName]),
TREATAS(CurrentYear, Dates[Year]),
TREATAS(CurrentDates, Dates[Date])
)
)))
RETURN SUMX(Result,[Count])
TEST
Date range: {5/27/2021…5/31/2021}
I am sure this can be improved but as I said at the beginning it is just an idea. Cheers!
In this case the easiest way is to implement a role playing dimension functionality by duplicating your date table. Power BI engine does not support role playing dimensions, so the workaround for small tables is just duplicating them, as described in this article.
In your case, you could create a table "Date_for_closed" using
Date_for_closed = ALL('Date')
This creates a copy of your original Date table. Then you can create relationships and only have active ones. This way it is even easier to maintain than a bunch of inactive relationships.
With this implemented you can build this:
from this source:
I have a table that looks like this. Table Screenshot
"FY 20-21 (Budgeted)", "FY21 Approved Budget" and "Revised Budget" are columns coming from three different data sources that I appended into one table. There isn't always data in all three of these columns, so I created a new column to consolidate the data with the following formula:
FY 20-21 Budget =
if(
and(
isblank('Comprehensive Budget'[FY 20-21 (Budgeted)]),
isblank('Comprehensive Budget'[FY21 Approved Budget])
),
'Comprehensive Budget'[Revised Budget],
if(
and(
isblank('Comprehensive Budget'[FY21 Approved Budget]),
isblank('Comprehensive Budget'[Revised Budget])
),
'Comprehensive Budget'[FY 20-21 (Budgeted)],
'Comprehensive Budget'[Revised Budget]
)
)
If both Budgeted and Approved are blank, use Revised.
If not, if both Revised and Approved are blank, use Budgeted.
If not, use Revised.
But if you look on the screenshot, if NONE of the columns are blank, it gives me Revised plus Budgeted. Where is the problem in my formula?
I have added your data here and found your Measure is perfectly returning your expected data as shown in the below image-
I Guess, there are some Aggregation issue in your case. You can right click on all column in the table visual properties and select Don't Summarize from the options. This should solve your issue I hope.
The picture I have attached shows what my power query table looks like (exactly the same as source file) and then underneath what I would like the final end product to look like.
Correct me if I'm wrong but I thought the purpose of power query/power bi was to not manipulate the source file but do this in power query/power bi?
If that's the case, how can I enter new columns and data to the existing table below?
You can add custom columns without manipulating source file in power bi. Please refer to below link.
https://learn.microsoft.com/en-us/power-bi/desktop-add-custom-column
EDIT: Based on your comment editing my answer - Not sure if this helps.
Click on edit queries after loading source file to power bi.
Using 'Enter Data' button entered sample data you provided and created new table. Data can be copy pasted from excel. You can enter new rows manually. Using Tag number column to keep reference.
Merge Queries - Once the above table is created merged it with original table on tag number column.
Expand Table - In the original table expand the merged table. Uncheck tag number(as it is already present) and uncheck use original column name as prefix.
Now the table will look like the way you wanted it.
You can always change data(add new columns/rows) manually in new table by clicking on gear button next to source.
Here is the closest solution to what I found from "manual data entry" letting you as much freedom as you would like to add rows of data, if the columns that you want to create do not follow a specific pattern.
I used an example for the column "Mob". I have not exactly reproduced the content of your cells but I hope that this will not be an issue to understand the logic.
Here is the data I am starting with:
Here is the Power Query in which I "manually" add a row:
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Mob", each if [Tag Number] = "v" then null else null),
NewRows = Table.InsertRows(#"Added Conditional Column", 2, {[Mob="15-OHIO", Tag Number="4353654", Electronic ID=1.5, NLIS="", Date="31/05/2015", Live Weight="6", Draft="", Condition store="", Weighing Type="WEAN"]})
in
NewRows
1) I first created a column with only null values:
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Mob", each if [Tag Number] = "v" then null else null),
2) With the "Table.InsertRows" function:
I indicated the specific line: 2, (knowing that power Bi start counting at zero, at the "headers" so it will the third line in the file)
I indicated the column at which I wanted to insert the value, i.e "Mob"
I indicated the value that all other other rows should have:
NewRows = Table.InsertRows(#"Added Conditional Column", 2, {[Mob="15-OHIO", Tag Number="4353654", Electronic ID=1.5, NLIS="", Date="31/05/2015", Live Weight="6", Draft="", Condition store="", Weighing Type="WEAN"]})
Here is the result:
I hope this helps.
You can apply this logic for all the other rows.
I do not think that this is very scalable however, becaue you have to indicate each time the values of the rows in the other columns as well. There might be a better option.