We create a monthly report in Power BI which requires creating multiple new tables, columns and measures from the data we import. Currently, the instructions for creating these tables is done manually, where we click on the new table or new column or new measure button and paste in the DAX code for that individual item.
I am a DAX newbie and was hoping to streamline the process. Can we create a multiple line DAX code that will create the tables as well as the measures and columns (in the correct table) that we only have to enter once?
Here is what I am asking for in psuedo-code:
Create Table A
Create Column 1 in Table B
Create Column 2 in Table B
Create Measure X in Table B
...
Create Measure Z in Table B
Create Table C
Related
I would like to merge 2 tables, Table3 and Table5 in Power BI.
Table3 is imported and Table5 was manually built in Power BI, as shown below:
I tried to use "Merge Query" feature in Power BI Desktop, with left join on Table3.Column1 and Table5.Name. I would expect to see the Table5 as highlighted in red, but instead there is only one option of Table3. How could I merge these 2 tables?
Table 5 is a calculated table and so cannot be merged in PQ. It has been derived from your model after PQ loads it. Create your table in PQ if you want to be able to merge it.
You can enter the values in Power Query by using Enter Data command, To see where to find it , check the picture.
Then create your table by manually entering values:
Then You can see the Table5 in Merge Dialog Box, see picture
Then: Combine (Merge) Tables
The result It returns:
Hi I am very new to PowerBI and come from Looker. In Looker there is the concept of derived tables which allow you to join the results of a query to the model for additional analysis (similar to a CTE in SQL).
For example, let's say I have a matrix that gets the number of transactions from the table 1 aggregated by the index group name from table 2. How could I join this back onto table 2?
I can export to csv and load into the data model although this is limited to 30k rows.
Please let me know what is best practice here?
How can I save the results from a matrix visualization as a table to the model for additional analysis in PowerBI
Is it possible to include columns from 2 different tables in DAX Switch Function ?
Both of my tables are linked by Many to Many Relationship.
I am trying to create a calculated column in Table A where I want to compare Columns from Table B, but I can't add the Table B column in the DAX Switch formula.
Any suggestions would be appreciated.
Thanks & Regards,
Pratik
Sample
Table B
Table A & Expected Result
In my opinion, it doesn't matter whether this table has many relationship, the only thing matter is that you are calculated based on your original table instead of calculate on a new measure, then result is unpredictable:
By create new table from the original table, and add column for the comment, I can provide result as your expectation, hope it solve your problem and accept the answer :)
Create new table from original table (Sheet1 is my old table) and select on ID column
Table = SELECTCOLUMNS(Sheet1,"ID",Sheet1[ID])
Create new column for comment
Column = SWITCH(LOOKUPVALUE('Sheet1'[Value],Sheet1[ID],'Table'[ID]), 0,"Matched with A","Matched with B")
The outcome for the new table:
Instead of trying to use two columns from two different tables for comparison in DAX, you can use the 'RELATED` DAX function to import a column from Table A to Table B or vice-versa. Then you can use this column for comparison in DAX.
Just set the appropriate relationship between Table A and Table B and create a new column with the RELATED DAX function to import the table that you want to use in the SWITCH function.
I need to create a measure with a logical DAX function that will iterate row by row between three tables and it will return me a virtual table of the rows that are in the first table and not in the other two.
My goal is to create a Maintenance Dashboard and I need to show how many activities were canceled.
The data is organized by the following:
Table 1 is dAcitivities0, this table is the first planning that happened in the begninning of the year.
Table 2 is the fReporgrammed, it shows me all the reprogrammed activities (dates) and it has the ID from dActivities0;
Table 3 is the fExecuted, it shows me all the activities that were executed and it is also filtered by dAcitivities with its ID.
My scenario is this: SalesValue have been entered for multiple sessions namely Lunch, Breakfast, dinner which is grouped by SessionKey in numbers. The same SalesValue repeats at times for 2 or more sessions for a given production plan date, based on MenuKey, RawMaterialKey and IngSFKey.
I need to use DAX query in Power BI to remove duplicated SalesValue based on ProductionPlanDate and SessionKey for a particular MenuKey in a given date.
I have attached the screenshot of a sample value range of SalesValue containing duplicate values for the same date across different sessions for your reference. For example, rows 7 and 14 have the same ProductionPlanDate, SessionKey, MenuKey, and SalesValue.
So you have a table with one "Grain" and you want to change the "Grain" by using a subset of the columns. Specifically you want only rows with distinct columns ProductionPlanDate, SessionKey, MenuKey and SalesValue
To do this in a DAX query you would use
evaluate
summarize
( 'table name'
, 'table name'[ProductionPlanDate]
, 'table name'[SessionKey]
, 'table name'[MenuKey]
, 'table name'[SalesValue]
)
You could provide this to create a calculated table or provide it to each measure that needs to work with this coarser grained data set.
However as it seems you are in Power BI the more appropriate place to do this would be to create your coarser grained table using Power Query (via the Edit Queries section of Power BI).
This is better than doing it in DAX as DAX is more tuned to analytics where Power Query is tuned to data transformation - and you want to do data transformation.
You can either keep the table that you have now alongside the new modified or replace it accordingly.
option A will just change your incoming table to have the new coarse grain.
option B will keep your original table and have the new grained table alongside it. Note that this will mean any Power BI visuals that you have created will need to be "rewired" to use the new table.
To do the transform in Power Query, the steps for both options are
Go to the Edit Queries area on PowerBI
Select the columns that you want to create the new Grain (i.e. ProductionPlanDate, SessionKey, MenuKey and SalesValue) by holding ctrl and clicking the column headers of each column in turn.
Right click on the column header for one of the selected columns and select "Remove Duplicates"
If you want option B, simply first copy the existing table by using "Reference" then do the same thing as follows:
Find your existing table on the left Queries section, r-click and click Reference
Rename the new table something appropriate
Apply the transform steps to the new table as above
Click Close & Apply and rewire any existing visuals that you need to use the new table
If you find you don't need your old table you can R-click on it in Power Query again and uncheck "Enable Load" so that PowerBI will not see it anymore.