Power BI, % Difference Between Two Columns - powerbi

I'm trying to create a measure on Power BI to show % difference between two columns, but I'm not getting the answer I expect.
On a pivottable I use the calculated field =('Actual'/'Standard Kg')-1 and it gives me a % deviation either side of 0 which works well.
I tried using the "Percentage Difference" quick measure in Power BI using the same two fields, but I get a totally different number.
I then tried the below code, which also gives me a different number:
% Dev =
DIVIDE (
SUM('Data'[Actual]),
SUM('Data'[Standard Kg])
) - 1
Neither of which gives me the number I expect and I can't figure out why. Any ideas?

Related

Average of calculated measure PowerBi

I'm new to DAX and Power Query. For days I've been having troubles with what should be a simple calculation. I need a solution for this problem, either using DAX or Power query or both.
I prepared the following example dataset to explain my case:
As you can see, I have a date column which contains date values of the 1st day of every 3 months (representing year quarters). The second column contains integer values.
I need to get the interannual variation of those values, and then, the average over those results.
Calculating interannual variation is pretty simple, I just made a calculated measure with the following formula:
int_variation = IF(
ISBLANK(DIVIDE(SUM(Data[Value]),CALCULATE(SUM(Data[Value]),SAMEPERIODLASTYEAR(Data[Quarter])),BLANK())),
BLANK(),
(DIVIDE(SUM(Data[Value]),CALCULATE(SUM(Data[Value]),SAMEPERIODLASTYEAR(Data[Quarter])))-1)
)
Getting the following results:
Now, the problem comes when I try to get the average of those calculated interannual variations.
I've tried using AVERAGEX DAX function like this:
avg_int_variation = AVERAGEX(Data,[int_variation])
Also tried adding VALUES function as suggested here:
avg_int_variation = AVERAGEX(VALUES(Data[Value]),[int_variation])
But returns a blank value in both cases:
Since the query must be dynamic (that means number of quarters may change) is not that easy as querying a sum of the last 4 values and divide the result by 4. What I need is a formula that takes all values in the dataset, calculate the interannual variation of all of those values(I guess that is done so far) and then return the average for those values regardless of how many values ​​are.
Important facts:
• In addition to the average I also need the standard deviation of the interannual variation values.
• I must use only PowerBi.
Example of the final result I'm looking for (done in Excel):
As I said above, a DAX and/or Power Query solutions are viable. Could you make it?
You can download my sample PowerBi report here if you want to use it.
Thanks in advance.
use the following measures to calculate the avg and standar deviation:
Average:
AVG = AVERAGEX( VALUES( Data[Quarter] ), [int_variation] )
Standar Deviation:
ST = STDEVX.S( VALUES( Data[Quarter] ), [int_variation] )
Hope it helps you.

Use the value of a card in the calculation for another card

Im using a powerbi file with two tables that by itself have no relation. I have created a page that shows two cards that both show the SUM of one of the tables. What i would like is to have a third card that shows the sum of the other two cards.
I have been searching the internet to even see if this is possible however the results i found are all for slightly different scenario's.
There is no code to show for this problem.
What i would like is to have a card showing the SUM of the values that are on other cards, thereby comining two datasets.
You need a measure.
create a measure for table 1 sum - use it in card visual 1.(Measure 1)
create a measure for table 2 sum - use it in card visual 2.(Measure 2)
Now, finally create another measure that is measure1 + measure2 - put it in the
third card visual.
For details, look at the answer here by RADO :- Power Bi Desktop - How to add values between tables?

Wrong Total in Power BI

I am creating a measure, Measure = divide(sum(amount),count(task)), this is giving me incorrect total.
This is what I am getting in Power BI.
Now the result which is expected here is
Basically what I want is to get the total of the measure that I have created, Power BI is dividing the total sum with the total count.
The answer could be quite mundane.
Instead of the Measure = divide(sum(amount),count(task)) you may instead be wanting to use:
Measure = SUM(amount)
The divide(sum(amount),count(task)) measure is a longhanded way of calculating the mean (AVERAGE being the shorthand way). But what you seem to require is the SUM.

Can't find DAX function to correctly calculate Sum

I run a simple query in SQL:
select count(*) FROM Abattoir.RecordScan_BloodPit
JOIN Abattoir.RecordScan RS ON RS.ScanId = RecordScan_BloodPit.ScanId
WHERE rs.HarvestDate = '07/16/2018'
which gives me a correct number of rows (say 2000)
I then go to my measure editor in Power BI, and enter:
CALCULATE(COUNT(BloodPit[ScanId]))
and get an insane number of around 254000000.
I don't understand why counting on a field so simply would give me a completely Different number.
New to DAX so my Google strings might not be the best when conducting searches.
Here is what the report looks like. Please note the nubers inside the rectangle are what I'm trying to calculate. The numbers vary from day to day...

Power BI DateDiff seems to return incorrect number of days

I'm using DAX DateDiff in Power BI to calculate the number of days between two dates, like this:
DaysDiff = DATEDIFF('MyTable'[Sales Order Date],
'MyTable'[Paid Date],DAY)
The formula is however returning some odd looking results, such as:
I would expect to see the actual number of days between the dates. For example, the number of days between 3/31/2017 and 12/4/2017 should be 248.
Both source columns are formatted as dates, and appear in the actual data as shown here.
How should the difference be calculated? I also tried a different formulation, which returns the same result:
DayDiff = 1.* ('MyTable'[Paid Date]-'MyTable'[Sales Order Date])
From the hint of the DaysDiff, my guess is that you have multiple records with same Sales Order Date and Paid Date, and Power BI has aggregated (default Sum) the results of all to one number.
If you change the summarization to either Average/Minimum/Maximum it should work fine.