Displaying Max, Min, Avg across bar chart Tableau - max

I have a bar chart with X axis as discrete date value and Y axis as number of records.
eg: x axis (Filtered Date)- 1st Oct, 2nd Oct, 3rd Oct etc
y axis (Number of Records)- 30, 4, 3 etc
Now, I have to create a table to get Max, Min and Avg. Value of the 'Number of Record'.
I have written a Calculated Field as MAX([Number of Records]) to get the maximum of Number of Records in this case 30 but I always get a value of 1.
How do I define the values to get max, min and avg. ?
Thanks,

Number of Records is an automatically calculated field that tableau generates when importing a datasource. You can right click on it and see the definition of the calculation: 1.
As you currently have your field defined, tableau will look for the maximum value of the column. It will always be 1 because that is the only value in that field for every record.
It sounds like you are actually trying to calculate the maxiuum of the sum of the number of records for your aggregation level (in your case date). You should be able to easily accomplish this using Level of Detail (LOD) expressions, or table calculations. Something like the following:
WINDOW_MAX(SUM([Number of Records]))

Related

How can I turn this into multiple line plots?

I assigned the x - axis as the number of days, 365, and my response variable for y-axis. However, upon using seaborn, it sets my x-axis as the whole number of rows I have.
Dataset
sns.lineplot(x="DATE", y="TMEAN", data=TS, hue="YEAR", style="YEAR") plt.show
Lineplot Result
I tried to use pivot and melt, but to no avail.
An easy way to fix your problem is to use the "day of the year" instead of the column "DATE". You can extract that as a separate column from the date like in this example:
data = {'DATE': pd.date_range(start='2013-01-01', end='2021-12-31'),
'YEAR': pd.date_range(start='2013-01-01', end='2021-12-31').year,
'DAY': pd.date_range(start='2013-01-01', end='2021-12-31').dayofyear,
'TMEAN': your_temp_data}
TS = pd.DataFrame(data=data)
sns.lineplot(data=TS, x='DAY', y='TMEAN', hue="YEAR")
plt.show()
Here, the "dayofyear" gives you your x-axis (being each day without the information of which year the temperature belongs to) and the coloring hue visualizes the year.

Caculating % Change Measure in Power BI

I have a table with 3 fields: Date, Name, and Index Value. I am trying to create a measure which will calculate the % change in Index Value over a filtered period per Name.
So if when I create a chart and adjust the time period (date period) the measure will adjust the calculation to find the % change in index value over that time period.
Here is a screenshot of some example data (which matches my dataset):
And here is a the data as text:
Date,Name,Index Value
30/09/2022,Company A,100
01/10/2022,Company A,101
02/10/2022,Company A,103
03/10/2022,Company A,101
04/10/2022,Company A,100
05/10/2022,Company A,101
06/10/2022,Company A,103
07/10/2022,Company A,101
08/10/2022,Company A,102.5
09/10/2022,Company A,103
10/10/2022,Company A,103.5
30/09/2022,Company B,104
01/10/2022,Company B,104.5
02/10/2022,Company B,105
03/10/2022,Company B,105.5
04/10/2022,Company B,106
05/10/2022,Company B,106.5
06/10/2022,Company B,107
07/10/2022,Company B,107.5
08/10/2022,Company B,108
09/10/2022,Company B,108.5
10/10/2022,Company B,109
So in this example the measure would calculate the % change for Company A and Company B over any time period, but for example it could be between 30/09/2022 to 08/10/2022
I have tried to calculate a measure - here's the code (although it's incomplete but hopefully will give you an idea of where I was trying (and failing) to go)
% Change = DIVIDE(CALCULATE(SUM(Returns[Index]),filter(ALLSELECTED(Returns),
Returns[Name] = earlier(Returns[Name]) && Returns[date] =
MAX(Returns[date] , ))))
So what I am trying to do here is divide the index value at the maximum date associated with each Name in the dataset by the index value associated with the same name at the minimum date. This will give in effect an 'end value' and a 'start value' per name and the % change is simply end_value/start_value - 1.

Power Query (M language) 50 day moving Average

I have a list of products and would like to get a 50 day simple moving average of its volume using Power Query (M).
The table is sorted by product name and date. I add a custom column and applied the code below.
if [date] >= #date(2018,1,29)
then List.Average(List.Range(Source[Volume],[Volume]-1,-50))
else ""
Since it is already sorted by date and name, an if statement was applied with a date as criteria/filter. However, an error occurs that says
'Volume' column not found in the table.
I expect to have an added column in the power query with volume 50 day moving average per product. the calculation to be done if date is greater than or equal Jan 29, 2018.
We don't know what your columns are, but assuming you have [product], [date] and [volume] in Source, this would average the last 50 days of [volume] for the identical [product] based on each [date], and place in a new column
AvgAmountAdded = Table.AddColumn(Source, "AverageAmount", (i) => List.Average(Table.SelectRows(Source, each ([product] = i[product] and [date]<=i[date] and [date]>=Date.AddDays(i[date],-50)))[volume]), type number)
Finally! found a solution.
First, apply Index by product see this post for further details
Then index again without criteria (index all rows)
Then, apply below code
= Table.AddColumn(#"Previous Step", "Volume SMA(50)", each if [Index_byProduct] >= 50 then List.Average(List.Range(#"Previous Step"[Volume], ([Index_All]-50),50)) else 0),
For large dataset, Table.Buffer function is recommended after index-expand step to improve PQ calculation speed

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

Sum Formula Crystal Reports Inquiry

Ok, say I have a subreport that populates a chart I have from data in a table. I have a summary sum field that adds up the total of each row displayed. I am about to add two new rows that need to be displayed but not totaled up in the sum. There is a field in the table that has a number from 1-7 in it. If I added these new fields into the database, I would assign a negative number to this like -1 and -2 to differentiate it between the other records. How can I set up a formula so that it will sum up all of the amount fields except for the records that have an 'order' number we will call it of either -1 or -2? Thanks!
Use a Running Total Field and set the evaluate formula to something like {new_field} >= 0. So it will only sum the value when it passes that test.
The way to accomplish this without a running total is with a formula like this:
if {OrderNum} >= 0 Then {Amount}

Resources