Power BI - Subtract values from same row - powerbi

I have the following output from two tables.
Item# Desc Sales Rank1 Company Sales Rank2 Rank Diff
1 Wigit1 500 1 ABC 15 32 31
2 Wigit2 300 2 XYZ 80 16 14
Rank1 data is from table A and Rank2 data is from table B. Both tables are tied together with the Item#. I'm trying to correctly get the Rank Diff to calculate from Rank2 - Rank1.

Do this in Power Query with a simple merge and add a Custom Column with the arithmetic. This can all be achieved using the menu and options, no code required. This is the same as in Excel, so here's a walkthrough from Microsoft that goes through all the steps you might need. Once you start using Power Query you won't look back. Good Luck!

if you don't have excess to 'Transform Data'( Power Query new name), then simply go to modelling tab and create a new column
Rank_Diff= TableName[Rank2]-TableName[Rank1]

Related

Power BI - How do I use calculated values from various tables and store them in a separate table

I'm trying to figure out a solution to my problem. Basically we get a monthly report with about 3000 records and there's a bunch of reporting that is done on that, and there are calculations based on various columns. e.g.
Date
Total usage
Recommended reduction
Product
01.01.2022
1000
500
A
01.01.2022
1300
70
B
01.01.2022
2000
900
C
...
...
...
At the end of it Power BI kindly sums up the columns which is great, but now what I am trying to do is take the sum of these columns and store them in a summary table so that it would be something like this so that I could use it for a time series visual
Month
Sum Total Usage
Sum Recommended Reduction
January
59720
12040
February
81020
20580
...
...
...
I have no idea how to go about doing this. Is this the right way to go ? Or is there a way to create a visual without having to create a summary table ? I'm at a bit of a loss, so any suggestions would be really appreciated.
You don't need any DAX calculations for that. Simply pull your data onto the fields of a line chart visual like shown below. Note that you have to drill-down from Year to Month to actually see the lines.

Running total vertically - Power BI

I have a dataset:
If I were to create a payment inflow matrix per a cohort where payment created_date is in columns and created date formatted as a cohort is in rows, it will look like:
I need to calculate running total per a column - see below:
There could be other fields in the table, e.g. product type which should influence running total.
I've seen the standard solution with = calculate(sum([X]), all(table), [date]<=max[date]) but I cannot make it work. What am I doing wrong? .pbix is uploaded at https://drive.google.com/file/d/1E3qJyOv11xSOlVRHAL9uq2C1Zho-g3zc/view?usp=sharing
You can use one of Power BI's build-in Quick measures:
This will give you the following result:
However, you won't get any aggregation for Jan and Feb since there are no according records in 2022-2. It looks like created_q is actually order_q?
When this is important, you would have to add dummy zero amounts with 2022-2 order_date.

Trying to make a date slicer which includes both date and time

I have a table of many datetime datapointname value triplets from process probe sensors.
I want to have a slicer which I can use to pick from time1 on day 1 to time2 on day 2
So my approach has been to have three slicers [Time Start] [Date Slicer] [Time End]. I have the data table and two time tables in 30 minute intervals so I have been able to create measures and display cards to show on the report the start and stop datetime combo.
I try to combine all this into a new table using DAX which filters the data table using the measures that I have but have not had any success.
Does anyone how how to set up a slicer or set of slicers so I can filter my report (for example), from 2022-Jun-15 at 4:30 PM to 2022-Jun-18 at 10:00 AM?
I am just learning about DAX. I have spent a few hours at this with no sucess.
Thanks
That's probably not a good idea from a modelling perspective. Data modelling best practice suggests that your Date (where 1 row = 1 day) and Time (where 1 row = 1 second or 1 minute, as necessary) dimension tables should be separate.
I would therefore recommend you setup your model in such a way that you have these two dimensions as two separate tables. You should then just be able to have two slicers - one from each table - to do what you need.
Note: this of course means that your fact tables will need to have separate columns (one for the date and one for the time) to join to your Date and Time dimension tables.

A table in my model records building valuations over time. Is it a slowly-changing dimension table or a fact fable?

I'm building a data model for a report that allows users to analyze building valuations over time, and details about buildings and their current leases.
I have a fact table that contains leasing information, and a dimension table that contains building information.
I have a third table that measures building valuations recorded every other quarter. I want to know whether it should be considered a slowly-changing dimension table or as another fact table.
The structure of the tables is as follows.
Fact_Leases
Lease ID
Building ID
Floor
Customer
Start Date
End Date
Occupied Area (sq ft)
Yearly Rent
101
1
1
Customer X
1/1/2000
1/1/2020
60
$10
102
1
2
Customer X
1/1/2010
31/12/2030
40
$25
103
2
3
Customer X
6/1/2015
5/8/2032
15
$17
104
2
1
Customer Y
5/6/2016
6/9/2028
5
$12
105
3
1
Customer Z
4/3/2017
12/2/2020
50
$19
Dim_Buildings
Building ID
Building Name
Sq Ft
Units
1
Building 1
100
10
2
Building 2
150
20
3
Building 3
125
50
?_Valuations
Building ID
Quarter
Valuation
1
Q2
$50
1
Q4
$55
2
Q2
$40
2
Q4
$35
3
Q2
$32
3
Q4
$44
At first, I thought the Valuations table was a dimension table because it relates to information about the building dimension. I considered joining the valuation data to the building dimension table but this would result in needlessly repeated rows, so I left it as a separate table.
However, the valuation table will not be used to filter the leases table, and the valuation column would be considered a measurement, which makes me think it is actually another fact table.
Can anybody clear this up for me?
Short answer: Yes. It is a fact table.
You have two fact tables that differ only in terms of granularity. Your Fact_Leases table, for example, is a fact table at the granularity of a lease. I can assume this quite safely because it appears the Lease ID column is a primary key. Each row of that table represents a lease.
On the other hand, your ?_Valuations table is a fact table at the granularity of quarter-time-building. That is, each row not only represents a building but also a quarter time period. And one way you can sort of know that this is a fact table is by understanding that if you had a date-dimension table, you could relate the two on their Quarter columns (although it would be a many-to-many relationship). Therefore, your date-DIMENSION table would be explaining the facts of your valuations. (I'd recommend, however, replacing your Quarter column with actual dates, and allow the date-dimension table to inform the quarters. That's an aside, though.)
Now, the problem of repeating valuation metrics occurs because you are trying to combine two fact tables at different levels of granularity. When you try to apply the valuations to the Fact_Leases table, which is at the granularity of lease, Power BI (or any BI tool, for that matter) can't understand how to apportion the valuation at the BUILDING level down to the LEASE level of granularity. So it just repeats. And it's important to keep this in mind when developing your reporting. No visualizations built at the context level of lease will be able to include a valuation metric because valuations exist only at a higher level of granularity.

Power BI DAX Sum By Year

Very new to Power BI and DAX and would appreciate a push in the right direction with this, seemingly simple, scenario, please. I have the following dataset:
Job Name Quarter Year Cost
alpha 1 2019 210
alpha 2 2019 100
alpha 3 2019 90
alpha 4 2019 28
beta 1 2020 100
kappa 1 2019 100
kappa 2 2019 90
beta 2 2020 100
beta 3 2020 75
beta 4 2020 30
kappa 3 2019 10
kappa 4 2019 30
All I am trying to do is get a measure/calculated column which calculates the total [Cost] per [Job Name] for each year. So for example I would get, for alpha, the value: 428. For kappa it would be: 230.
Thanks!
Use the below DAX to obtain the above result:
New Table :
SUMMARIZE('Table','Table'[Job Name],"New Column",SUM('Table'[Cost]))
Using SUMMARIZE (as #Shilpa suggests) will return/add a new table to your report data source. I think this is not your requirement.
As you are looking for a solution using a measure or a calculated column, lets know a bit details about them as they are not same with the functionality-
Calculated columns:
Evaluated for each row in your table, immediately after you hit 'Enter' to complete the formula
Calculate new values from existing values for each specific rows. For example, if you have value 5 in column "A" and 4 in column "B", you can create a new Calculated column C as (A x B) which will store the result 20. This will generate results in all rows using the calculation (A x B).
Result in Calculated column saved to the model as like other column's value.
Measures:
Evaluated when you use it in a visual and the visual is rendered
Measure always holds the aggregated value like - SUM, AVERAGE, COUNT.
Not saved anywhere (well, actually there's a cache in the report layer but it's not part of the file when you hit Save)
Now, for your scenario/requirement I think you need a simple measure as below-
total_cost = SUM('your_table'[Cost])
Your measure is ready now. Just pull column "Job Name" and measure "total_cost" to you visual. You will get your expected output. You can use slicer to check your value in/for different dimension. Just play around :)