PowerBI - Draw Line Chart with X Axis Grouped by Date (in Days), When Column contains Full timestamp? - powerbi

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
)
)

Related

Struggling with PowerBI slicer logic and process

I've tried to be "clever" setting up a slicer for improved visual experience, but it is not working as expected.
The slicer is based on a manually created table with two options:
This leads to a slicer which is compact and intuitive for report users (multi-select allowed):
I can then create a couple of measures that record all possible truth states of the slicer, e.g.
HideInactivePathSelected = --Truth status of slicer selection
IF (NOT ISFILTERED(SlicerHideOption),FALSE, --If no slicer options selected
IF(SELECTEDVALUE(SlicerHideOption[Options]) = "Hide inactive/former pathologists",TRUE, --Specific option selected
IF(COUNTROWS(VALUES(SlicerHideOption)) = 2,TRUE, --If both slicer options selected
FALSE --If all else fails
) ) )
This can be confirmed using a simple table, which updates instantly and correctly when the slicer is changed e.g.:
The problem is, at this point, if I try to refer to the state of the measure HideInactivePathSelected, things no longer work.
For instance, if I create a calculated column that refers to the measure state, this does not work. Consider this simplified example:
test_value =
IF([HideInactivePathSelected] = True, 2, 0)
If I then make a test table or chart based off test_value, changing the slicer has absolutely no effect.
I suspect I have tried to be "too clever" and perhaps I have misunderstood the (non)dynamic nature of calculated columns. Can some kind soul tell me what I have done wrong? Is this approach salvagable or do I need to start again?
Using PowerBI RS Desktop May 2021 edition.
Measures in calculated column do not see the row context, so you have to do context transition using Calculate function, e.g.:
test_value =
IF( CALCULATE( [HideInactivePathSelected] ) = True, 2, 0)
It should be easier to solve your issue if you provide some example data. There are better and more efficient ways to achieve the goal of filtering data in whole page, than using the measure and then calculated column.

Create a pivot table in Power BI with dates instead of aggregate values?

I have a table of companies with descriptive data about where we are in the sales stage with the company, and the date we entered that specific stage. As can be seen below, the stages are rows in a Process Step column
My objective is to pivot this column so each Process Step is a column, with a date below it, as shown in excel:
I tried to edit the query and pivot the column upon loading it, but for the "aggregate value" column, no matter which column I use as the values column, it results in some form of error
My advice would be not to pivot the table in the query and use measures to get dates that you want. The benefit of not doing so is that you are able to perform all sorts of other analytics. For instance, Sankey chart would be hard to do properly with pivoted table.
To get the pivot table you are showing from Excel, it's as simple as using matrix visual in Power BI and putting Client code in rows and Process Step in Columns, then Effective date in values.
If you need to perform calculations between stages, it's also not too difficult. For instance, you can create a meausure that shows only dates at certain stages, another measure for another stage, and so on. For example:
Date uploaded = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Upload"))
Date exported = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Export"))
Time upload to export = DATEDIFF([Date uploaded], [Date exported], DAY)
These measures will work in the context of client and assuming there is only one date for the upload step (but no Process step in rows or columns). If another scenario is needed, perhaps a different approach could be taken.
Please let me know if that solves your problem.

Can a measure be created in Power BI that references two tables that share no relationship?

I'm trying to create a matrix table in Power BI to display the monthly rent projections for a number of properties. I thought I could simply create a measure that summed the rent from one table and then displayed it by month based on start and end date conditions, but it's been a while since I created any measures and I had forgotten that there needs to be a relationship between columns, among other things.
Data Model
A site can have more than one lease associated with it and a lease can have both car-parks and floors associated with it, of which there can be multiple.
In addition to the tables in the linked image, once I had sorted out what I thought would be the easy step I was going to add another table which includes the estimated percentage rent increase and the period in which the increase will occur.
I started out by trying to create a measure along the lines of the following:
Matrix Test =
IF (
HASONEVALUE ( Period[Month] ),
IF (
Period[Month] >= Leases[Custom Start Date],
SUM ( Floor_Rent[Annual Rent] ) / 12,
0
),
0
)
This would need to be expanded upon because the end date of a lease would also need to be taken into consideration.
As well as forgetting about the relationship requirements, I've forgotten how to deal with the issue of narrowing down to a single value within a column.
The result is supposed to be something that looks like this:
The blanks indicate a lease that starts in the future or ends within the time-frame displayed.
When I try linking the Leases table and the Period table on Leases[Start month for current term] and Period[Month] all I can get to is a table that shows the rent amount in the month the lease starts.
Is what I'm trying to achieve possible? If so, how do I accomplish the desired result?
Link to .pbix file
Solution
The direct answer to the title question is probably 'no', but while trying to figure out how I could use Pratik Bhavsar's LOOKUPVALUE suggestion I had a thought and performed a clumsy google search - power bi create table for each value in column - and found this post. By meddling with some of the DAX in said post I was able to come up with the following:
Test Table =
GENERATE(
SELECTCOLUMNS(
VALUES(Leases[Lease ID]),"Lease ID",[Lease ID]
),
SELECTCOLUMNS(
VALUES(Period[Month]),"Month",[Month]
)
)
The result is a table with each Lease ID mapped against each Month. I can't claim to understand exactly how the functions work, and it's not the outcome I thought I needed, but it allows me to achieve exactly what I set out to do.
I've accepted Pratik Bhavsar's answer because it effectively accomplishes the same thing as the work around I implemented. Pratik's solution might be better than what I eventually landed on, but I need to have a closer look at how the two compare.
The following DAX will give you a table with all buildings mapped against all rows in the period table, eliminating the requirement of a relationship.
SiteToPeriod =
CROSSJOIN(
SELECTCOLUMNS(Sites1, "Building name/label", Sites1[Building name/label]),
Period
)

Sumif using page, report and visual level filters

I have two tables that are related by an ID column called 'Program_Code' (1:Many).
'Program_Summary':
Program Code = each row has a unique ID, e.g. HI-18, HI-17
Program Name = name of a program, e.g. Home Improvement
Incentive Spending = calculate(sum(Program_Data[Incentives]))
'Program_Data':
Program Code = many rows with the same ID
Incentives = incentive amount to summarize in Program Summary table
Record Status = Claimed, Pipeline or Rejected
Record Fiscal Year = 2017, 2018 or 2019
I created a Power BI table that has rows organized by 'Program Name'. Note that each program name like "Home Improvement" may have more than one code associated with it, e.g. HI-18 and HI-17 corresponding to fiscal years.
I'm hoping to summarize Incentive Spending by program name, and use page/report level filters to restrict results. The Report Level filters are:
Record Fiscal Year = 2017
Record Status = Claimed
But, the calculate(sum(Program_Data[Incentives])) filter ignores these page level filters. How do I fix this?
You created "Incentive Spending" as a calculated column. Instead, you need to create it as a measure.
Calculated columns are calculated only once - when you create them, or when you reload data. After that, calculated columns contain only static data, and can not respond to any filters.
Measures, on the other hand, are dynamic formulas that recalculate any time you change any filters.
To fix your problem, simply create a new measure from "Modeling" tab:
and add DAX code:
Incentive Spending = SUM(Program_Data[Incentives])
(no need to use CALCULATE here).
Drop this measure into a table or matrix, and it should work. Instead of page/report level filters, I'd recommend to use slicers - create a slicer for Fiscal Year, and another slicer for Record Status. They will allow you to filter the calculation with ease.
You can use:
CALCULATE(sum(Program_Data[Incentives]);Program_Data[Record Fiscal Year] = 2017 && Program_Data[Record Status] = "Claimed")
However, I do not understand why you would need this because you have 2 tables with the right link, this should give you all possibilities with the table/matrix visualization what you need to show correct results..

Is it possible to use a slicer as a parameter to a DAX Summarize function?

I have a FactLosses Table, and a DimAccumulation table. I have brought them into PowerBi and I have placed a slicer to choose which accumulation zones i am interested in.
Once the user has selected the zones, i want to perform a group by year on the losses and sum the losses into year buckets. But only on the data that applies to the zones the user picked.
I am using the following DAX code to do the group by like so...
Table = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
The problem is the new table always produces the same result. i.e When i make changes to which accumulation perils should be included it makes no difference to the summation. (it is summing the entire table)
I'd like to use the slicer to filter the fact table and then have the DAX query run on the filtered list. Is this possible?
If you want these tables to be responsive to filters or slicers on your report, then you can't write these as calculated tables that show up under the Data tab since those are computed before any filtering happens.
To get what you want, you have to do everything inside of a measure, since those are what respond to slicers. If you're looking for the max loss year once the grouping and summing are completed, you can write a measure along these lines:
Year Max =
VAR CalculatedTable = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
RETURN MAXX(CalculatedTable, [Losses By Year])
Writing it this way will allow the calculated table to respond to your slicers and filters.