DAX - Calculate grand total - dax

I have a data file as below
TOTALUNITS TOTALRECEIPTS
55529 12806357
45472 6813097
19605 4217647
19202 2105760
17114 2568849
16053 1577361
1506 657607
I need to write a measure to calculate the average of TOTALUNITS. The measure should give me a result as (TOTALUNITS/SUM(TOTALUNITS))*100 as below
TOTALUNITS TOTALRECEIPTS %TOTALUNITS
55529 12806357 31.8%
45472 6813097 26.1%
19605 4217647 11.2%
19202 2105760 11.0%
17114 2568849 9.8%
16053 1577361 9.2%
1506 657607 0.9%
Someone help me with this.

If you want this as a measure that will sum to 100% of what you have filtered, then try this:
%TotalUnits = DIVIDE(
SUM(Receipts[TotalUnits]),
CALCULATE(
SUM(Receipts[TotalUnits]),
ALLSELECTED(Receipts)))
If you try this as a calculated column though, you'll get 100% every time. If you want to do this as a calculated column, then you'll need to remove the SUM from the first argument of DIVIDE:
%TotalUnits = DIVIDE(
Receipts[TotalUnits],
CALCULATE(
SUM(Receipts[TotalUnits]),
ALL(Receipts)))
Calculated columns are not responsive to slicers or filtering on the report page. They are computed once when the data is loaded or refreshed, but not dynamically interactive.

Please try this, and format as Percentage:
%TotalUnits =
DIVIDE(
SUM(Receipts[TOTALUNITS]),
CALCULATE(
SUM(Receipts[TOTALUNITS]),
ALL(Receipts)
))
Edit: Receipt is the table name

Related

Calculate Total Amount for a specific period

I want to calculate total value between two dates in DAX. I have a formula SUM(C5:C16) in excel sheet, which C5 is the sales amount for a specific date (last year + 1month), and C16 is the sales amount for current row date.
I tried this formula in DAX, but it did not return sum value:
var Rolling = CALCULATE(sum('proces'[HOURS]),DATESINPERIOD('Date'[DateField],ENDOFMONTH('proces'[date_start]),-12,MONTH))
Also, I tried this one, but it is not working:
=SumX (
var prev=DATEADD(DATEADD('proces'[date_start] ,-1,YEAR),+1,MONTH)
return
Filter ( 'proces',
'proces'[date_end] <= Earlier ( 'proces'[date_end] ) &&
'proces'[date_start]>=prev,
'proces'[HOURS])
Also, I tried this one but it returns nothing
=CALCULATE(
SUMX('proces','proces'[HOURS]),
DATESBETWEEN(
'Date'[DateField],
STARTOFMONTH(DATEADD(LASTDATE('Date'[DateField]),-1,MONTH)),
ENDOFMONTH(DATEADD('Date'[DateField],-1,MONTH))
)
)
You seem to be confused about variables in DAX and your formulas are not even valid DAX expressions. Learn about variables in the official documentation:
Use variables to improve your DAX formulas
If you need further help with calculating the your total amount, add sample data to your question.

DAX Count measure values between given range

I am trying to create a measure that would count the instances when another measure is between given values.
The first is a measure of forecast accuracy, which is calculated over products and customers with a target value of 1. Then I would like to make a monthly report which shows for how many products the forecast accuracy is less than .85, between 0.85 and 1.15 and over 1.15.
The measure I tried for the middle category, which does not give the desired result:
var tab = SUMMARIZE(data, data[ComponentNumber], "Accuracy", [Forecast accuracy])
return SUMX(tab, IF([Accuracy] > 0.85 && [Accuracy] < 1.15, 1, 0))
The data table has also a customer number, which is why I tried first evaluating the measure [Forecast accuracy] only over components, disregarding the customers.
One source of the problem may lie in the fact that the measure [Forecast accuracy] is calculated as a division of two measures [Ordered Quantity] and [Forecast Quantity], of which the former is in another table. Does this affect the evaluation of my attempted measure?

Total sum based on Expression Detail Items (SUM IF Line Items)

I have a table showing Turnover.
I used the same column but did a SUM IIF on the detail lined as follows:
=SUM(IIF(Fields!ID_Country.Value = 17,Fields!Turnover.Value,0))
and
=SUM(IIF(Fields!ID_Country.Value = 23,Fields!Turnover.Value,0))
17 = Great Britain
23 = Ireland
I then want to do a TOTAL per column based on my above detail rows. I just cannot find the right way to do it.
I Tried:
SUM(=SUM(IIF(Fields!ID_Country.Value = 17,Fields!Turnover.Value,0)))
But this does not work.
Please help as I am really stuck.
Thank you!
Because Turnover for GB is in Pounds and for Ireland they are in Euros, I want to split my columns and then do a final SUM for GB and Ireland.
I expect to see the grant total for per column for GB and Ireland summing my detail rows which have the expression calculation. (SUMIIF)
Table: Circled in RED is where I expect to see my TOTAL
enter image description here
Data Structure:
enter image description here

DAX Average Issue

I have this table
and this is the measurement i have to calculate the average
Traded Contract(MTD) := TOTALMTD(SUM([Traded Contract]), 'TestTable'([Trading Date]))
Average := [Traded Contract(MTD)]/SUM([Trading Days])
Currently the result of average is correct up to daily level,
When I wish to see the monthly average, I didn’t filter by date, then I will get the result 9000/14 = 642 which is incorrect, I wish to see 4425 which is the total of each average. How do I amend my Average measurement query to get the expected result
I'm not entirely sure why you would want to do this since 4425 isn't really an average, but you can write your formula as follows:
Average = SUMX(VALUES(TestTable[Trading Date]),
[Traded Contract(MTD)] /
LOOKUPVALUE(TestTable[Trading Days],
TestTable[Trading Date],[Trading Date]))
For more information on how these sort of measures work, I suggest reading the following article:
Subtotals and Grand Totals That Add Up “Correctly”

Create No to nearest Decimal in filemaker calculation

I have database where i am calculating the shipping cost. The logic of shipping cost is such way that it is calculated every 500gm. I have price list according to different weight but when i am using calculation taking the weight from user for example 1.4 i am unable to get it to next calculative weight of 1.5 , .7 to 1.0 , 1.7 to 2.0 how to achieve this?
Try this (substitute myNumber to get a different result):
Let (
[
myNumber=2.6;
myNumberInt = INT(myNumber);
myNumberFr = myNumber - myNumberInt;
myNumberFr = Case ( myNumberFr =0;0;myNumberFr >0.5 ; 1;0.5 );
result = myNumberInt + myNumberFr
]
;
result
)
You can wrap it in a custom function, in case you need to change it later throughout the system.
I am sure there is a better mathematical formula, but this should get you started
The Problem is fixed.
I have price list according to weight slab in different table.
I used the Country code with Zone id to track prices for particular weight slab prices provided by the courier company.
The price list for e.g. is in such way :-
Zone 1 .5Kg 100Yuan 1.0Kg 120 yuan etc etc , there goes till 20Kg in some case at max.
so when i input the weight in weight field for e.g. 13.5kg i use this weight / .5 which gives me a value 27 , the reason i use to divide the weight with .5 is for example if i input the weight to 13.8 kg i get 27.6 there upon i embed this in ceiling function in calculation field which gives me value of 28 which i can use to calculate the next price slab in the price list which is for every 500Gms +- .
Once i get this done i use this in script which does the job of going to particular layout to search the zone and the prices and retrieving those data to original layout to show the desired result.
Regards,
Soni

Resources