My direct Query structure img
I want to create a column in FB_DATA_AD_ONLY to get the VALUE of FB_ACTION_AD where the ACTION_TYPE="something" in power BI. I should keep the function " direct query". Do you think I can do this in Power BI ?
First, I would suggest looking at these site to understand the limitations of Direct Query (I know that I don't know all of the limitations).
Use DirectQuery in Power BI Desktop
Using DirectQuery in Power BI
Second, in the first one, it talks about a setting you can turn on to bypass some of the limitations Power BI imposes on Direct Query. To turn that option on, go to File -> Options and settings -> Options, then go to Direct Query and check the box next to Allow unrestricted measures in DirectQuery mode (Power BI will need to be restarted after checking that option).
With that option checked, you can create some new measures in the data. I have some basic sample data (created using this SQL script).
Click on the ellipses ("...") next the your FB_DATA_AD_ONLY table (I'll be using my Buildings table) and select New measure. Enter the following formula
NewMeasure = CALCULATE(
SUM(FB_ACTION_AD[VALUE]),
FILTER(
FB_ACTION_AD,
FB_ACTION_AD[ACTION_TYPE] = "something"
)
)
I used this formula.
EmpSum = CALCULATE(
SUM(Employees[idemp]),
FILTER(
Employees,
Employees[FirstName] = "Alex"
)
)
I threw together a quick table and matrix to illustrate that the measure is returning the expected value (Alex is only assigned to one building and their ID is 2, so that building would have a EmpSum value of 2).
Related
I've been trying to figure this for several hours now.
In my SQL table I have a full timestamp column, with date and time of the action, e.g. last time a user was logged in.
Say I have two users who logged in today so far, in different hours. I want to see "2" log ins for today's Date, instead of seeing them broken down further into exact timestamps.
See screenshot for example
What's the easiest way to do this?
EDIT:
Seems like the whole issues stems from my desire to use "Direct Query" method to load the data.
If I'm just importing the whole table (as users_table (2)), Then yes, I can create a new column with this syntax:
Column = 'users_view (2)'[last_active].[Date]
And plot the graph that I Want.
However, I am unable to create this column on direct query mode. Trying to create this column leads to an error:
Column reference to 'last_active' in table 'users_view' cannot be used
with a variation 'Date' because it does not have any.
If such basic functinoally is not possible, then what's the merit of Power BI? my use case is to create a REAL time dashboard.
Seems like if I want to have anything in real time, it means I can't build even the most basic graph, and vice-versa.
So either I'm missing something, or Power BI is worthless for real time reporting.
You need to follow these steps:
In your fact table, create a new column that corresponds to the date of the timestamp (this will be a grouping dimension column for your timestamps)
Add a measure that counts rows of your table
In a new chart, e.g. line chart, bar chart, whatever - use the date column as X-axis information, and the row count measure as your Y-axis information
Edit: Since it is now apparent you insist on using Direct Query for this - it would appear your data is not in the correct format to support what you want to do. The solution would be to provide Power BI with the correct format for the analysis you want to do. Like adding a column in your SQL database table.
A very costly way of calculating "something" useful would be to do a cumulative count based on timestamp that resets daily. This will look messy but for a site with a lot of activity it will be able to plot something. But it will be slow - since obviously we are far, far away from what would constitute a "sensible" use-case for Power BI using Direct Query.
Cumulative Daily Logins =
VAR _max_time = MAX ( users_table[last_active] )
VAR _date = DATEVALUE ( _max_time )
RETURN
COUNTROWS (
FILTER (
ALL ( users_table ) ,
users_table[last_active] <= _max_time
&& DATEVALUE ( users_table[last_active] ) = _date
)
)
I have a table in Power BI Desktop which has multiple columns (5 Dimension data connected with a Fact table - Star Schema).
I have now added 3 Slicer to filter data in above table but when I select the first slicer then the other slicers should show only available dimensions data but it is showing all the available data.
I tried changing Cross filter Direction to both from single in Manage Relationship but it works for only one column but not to all with the below error or warning message.
NOTE: I do have few more Pages in the same Visualization report which contains separate fact table with same dimension keys.
Please let me know how to resolve this or any other suggestions.
Use the following measure to filter through your dimensions
Cross Filter = INT( NOT( ISEMPTY( 'Your FACT TABLE') ) )
Then dragg this measure in every slicer into the filter pane and select the option is equal to 1.
My power bi version is in spanish but you will get the idea.
----------------------------------------
I am trying to replicate one of the tableau report into power bi. I am new to tableau and power BI so I am just learning from online and working on this project. Hence I have few questions in adding filters and grouping columns.
there is a custom query used in tableau to build the report. I am using the same report in power bi to replicate the same report. I have attached the code below. I have loaded the query in power bi and visualize the data. but I wanted to add the filters same like the tableau report has. but I am unsure how to add those in power BI.
Questions 1 : how do I add the filters to the power bi in a same way it is used in tableau(screenshots attached)
questions 2: in tableau filter "report date" is used a condition (report date >=adddate and reportdate<=dropdate. could you please help me how to create the same type of filter in power bi?
3. how do I group by the columns in power bi in the same way as tableau does?(screenshot attached)
Good you are trying to learn Power BI and tableau, two really great tools! I'm not going spoil your learning by precisely answering your questions, but I can give you some directions.
Try using the slicer visual and in the visual select drop-down.
This one is a bit more complicated in Power BI as it requires you to create multiple objects. First you should create a list of values for your parameter. You can do this using Create New Table and using the CALENDAR() function, it's called a calendar table. Combine it with a MIN() and MAX() function to get the first and last dates in your dataset.
Parameter = CALENDAR( MIN ( Table[adddate] ) ; MAX ( Table[dropdate] ) )
Secondly, you create a measure which will determine if a row in your table matches the criteria you specified. This needs to be a measure, as calculated columns do not accept variable parameters.
Included =
var _selectedDate = SELECTEDVALUE( Parameter[Date] ; MIN ( Parameter[Date] ) )
RETURN
SUMX (
Investments ;
IF (
AND ( Table[adddate] <= _selectedDate ; Table[dropdate] >= _selectedDate )
; 1
; 0
)
)
Add the measure to the visual filters of your matrix and make sure it filters for the value 1.
Finally, add the Parameter[Date] field to your report page and set it to the visual style slicer as mentioned in the answer to question 1
Try the matrix visualization and make sure that you drill down in the visual. Hover your mouse over it and select the branched arrow.
I want to create Quarter-on-Quarter % Change in Direct Query mode in Power BI
Creating measures like Quarter on Quarter percentage is quite easy is Import mode in power BI. But if we try them in Direct Query mode, the time intelligence measures are not available.
I even tried the DAX generated for Quarter-on-Quarter % Change in Import mode(as shown below) to do the same in Direct Query mode. But Time intelligence functions does not work in Direct Query mode.
Count of IssueId QoQ% =
IF(
ISFILTERED('services_user stat_view'[CreatedDate]),
ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
VAR __PREV_QUARTER =
CALCULATE(
COUNTA('services_user stat_view'[IssueId]),
DATEADD(
'services_user stat_view'[CreatedDate].[Date],
-1,
QUARTER
)
)
RETURN
DIVIDE(
COUNTA('services_user stat_view'[IssueId])
- __PREV_QUARTER,
__PREV_QUARTER
)
)
Could you please help?
Create a proper Date Table, and mark it as such.
And use that date table on your Time Intelligence. Should work as expected.
You are probably using FORMAT in your date configuration, which is not supported.
If you don't find it in these tables, then you cannot use.
Hope this helps!
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.