So, I have a table with many columns and what I am trying to do is increment the number of sales that have been in that hour and then reset it after after the next hour. I have tried to use summarize key word, but it doesn't seem to be letting me accumulate it. At the moment my data is in 15min bands so the data shows sales in that 15 minute time period. But I would like to accumulate it into next hour.
This is what I have now
15minperiod. Sales
09:00:00. 10
09:15:00. 10
09:30:00. 10
09:45:00. 10
10:00:00. 10
10:15:00. 9
10:20:00. 13
This is what I would like to get:
15minperiod. Sales Sales in hour
09:00:00. 10. 10
09:15:00. 10 20
09:30:00. 10 30
09:45:00. 10 40
10:00:00. 10 10
10:15:00. 9 19
10:20:00. 13 32
Yes, this can be done with a calculated column like this:
Sales in an hour =
var currentTime = [15minperiod]
return
CALCULATE(
SUM('Data'[Sales]);
FILTER(
ALL('Data');
'Data'[15minperiod] <= currentTime && HOUR('Data'[15minperiod]) = HOUR(currentTime)
)
)
Related
Hello I am just new in powerBI and it is still hard to work on for me.
I have a matrix like that
DATE Sales Refund
26 Agu 45 5
p1 10 3
p2 15 2
p3 20 0
27 Agu 60 1
p1 15 1
p2 20 0
p3 25 0
In the date parts I have subtotals as it normally does. However, I want to show the average of that day there and when I get the average I will make conditional formatting according to it. If a cell is below average I will mark it with red point and in refunds I will do it for the values above the average.
Is there a way to do that. I searched for it for awhile but could not find.
The output I want is like that. (star is for red point.)
DATE Sales Refund
26 Agu 15 1.66
p1 10* 3*
p2 15 2*
p3 20 0
27 Agu 20 0.33
p1 15* 1*
p2 20 0
p3 25 0
Thanks.
You can colour the background; For example, create this measure:
AVG =
IF( SELECTEDVALUE(RefundTab[Sale] ) < CALCULATE(AVERAGE(RefundTab[Sale]), ALL(RefundTab[Code])),0,1)
From menu -> Conditional formatting -> Background color:
And here:
OR
you can create measure where we return string instead of number where we put some unicode value:
SumSaleIf =
var _sale = sum(RefundTab[Sale])
var _IfAVG = CALCULATE(AVERAGE(RefundTab[Sale]), ALL(RefundTab[Code]))
var _check = if(_sale < _IfAVG, _sale & UNICHAR(128315), _sale &"")
return _check
I have the following dataset.
name duration date begintime time_type
Person 1 15 20190910 0845 AM
Person 1 15 20190910 1000 OV
Person 1 15 20190910 1100 AM
Person 2 15 20190910 0915 AM
Person 2 15 20190910 1015 AM
Person 2 15 20190910 0945 AM
Person 2 15 20190910 1045 AM
I trying to create a measure that will sum the duration by person, but because Person 1 has time type of OV on 20190910, I need to divide the sum by 5. If the person doesn't have a time type of OV for that day, I will need to divide by 8 (as Person 2 does not have time type of OV on that day). It is possible that Person 1 doesn't have a time type of OV on another day, but for that day I will need to divide by 8. How can I accomplish this in a PowerBi Measure?
UPDATE:
The expedected output should looks like this:
Person 1 - 9 (15 + 15 + 15) / 5
Person 2 - 7.5 (15 + 15 + 15 + 15) / 8
This measure will check if the values present in the context contain "OV", and based on that will choose the proper value for the division
Measure =
SUM('Table'[duration]) /
IF(CONTAINSROW(VALUES('Table'[time_type]),"OV")
,5 --true
,8 --false
)
If I understand your scenario, you apply the division on a daily basis, therefore the adjusted divisor can be different in different days. Then you should also interate over names, otherwise totals would be incorrect.
Adjusted Duration =
SUMX(
VALUES( TImes[name] ),
SUMX(
VALUES( Times[date] ),
VAR timeTypeOV =
CALCULATE(
COUNTROWS( Times ),
ALLEXCEPT( Times, Times[name], Times[date] ),
Times[time_type] = "OV"
)
VAR duration =
CALCULATE(
SUM( Times[duration] ),
ALLEXCEPT( Times, Times[name], Times[date] )
)
VAR divisor =
IF( timeTypeOV > 0, 5, 8 )
RETURN
DIVIDE( duration, divisor )
)
)
So I am programming in arm assembly on raspbian and I am trying to convert the epoch time using c/c++ libraries because that is what I am allowed to do, but I am confused as to how to do it. If I simply bl time it will give me the epoch time, but I am confused as to how I would get the return value in r0, then convert that into the local time in assembly using C or C++ libraries. I know localtime/gmtime and strftime exist, but its not as easy as getting the epoch and just bl localtime or bl strftime. Then I want to format it where I only get the local time and maybe am/pm. I am not interested in the date. I just need some helpful code, or some direction to be pushed into. Thanks
Edit: If its easier to just convert using math that would also be helpful
So to not do your homework for you, here is an example. All of this is basic grade school math, no magic.
If I have 345678 pennies how does that brake down into various dollar and coin amounts.
There are 100 pennies in a dollar and 100 dollars in a 100 dollar bill, so
345678 / (100*100) = 34 remainder 5678
Looking at units
pennies / (pennies/dollar * dollars/hundred) =
(pennies * dollars * hundreds) / (pennies * dollars )
pennies and dollars cancel out left with hundreds which is correct
so 34 hundred dollar bills with a remainder of 5678 pennies
repeat for 20 dollar bills
5678 / (100 * 20) = 2 remainder 1678
10 dollar bills
1678 / (100 * 10) = 1 remainder 678
5 dollar bills
678 / (100 * 5) = 1 remainder 178
one dollar bills
178 / (100 * 1) = 1 remainder 78
50 cent pieces
78 / 50 = 1 remainder 28
quarters (25 cents)
28 / 25 = 1 remainder 3
dimes (10 cents) 0 remainder 3
nickles (5 cents) 0 remainder 3
pennies the remainder 3
so 345678 pennies is equal to
34 100 dollar bills +
2 20 dollar bills +
1 10 dollar bill +
1 5 dollar bill +
1 1 dollar bill +
1 half dollar coin +
1 quarter +
3 pennies
check the work
34 * 100 * 100 = 340000
2 * 100 * 20 = 4000
1 * 100 * 10 = 1000
1 * 100 * 5 = 500
1 * 100 = 100
1 * 50 = 50
1 * 25 = 25
1 * 3 = 3
add that up you get 345678
If I simply wanted to know how many quarters
345678 / (25 * 1) = 13827 quarters with a remainder of 3.
it all works the same with 60 seconds per minute 60 minutes per hour 24 hours per day. 365 days for 1970, 365 days for 1971, 366 days for 1972 365 days for 1973 and so on
31 days for january, 28 days for february 2019, 31 days for march and so on
easier to adjust for timezone first 60 seconds * 60 minutes * hours of adjustment
add or subtract that off as needed, then work that number either through the years/months/days or if you simply care about time of day then you only need to divide by seconds per day. or you can divide by seconds per day and get total days as a result with fraction of a day as a remainder, the fraction of a day is the time of day today and the total days you can then later subtract off the years then months to find the date.
Extra credit, what year will computers with 32 bit time counters using the 1970 epoch have a Y2K like roll over event (causing crashes and death and destruction across the planet just like Y2K)?
The programming language is irrelevant until the algorithm is understood and ideally coded in a favorite high level language, to confirm/prove the algorithm. Then port that knowledge to some other programming language.
Shortcutting the steps will sometimes get you there faster but when the shortcut fails it fails in spectacular fashion.
I am trying to calculate the average of a column in a measure in DAX, but I have the problem that the values are duplicated on multiple rows.
The data looks like this:
Line ID Value
1 1 10
2 1 10
3 1 10
4 1 10
5 1 10
6 2 40
7 2 40
8 3 90
9 3 90
10 3 90
When I do
sum(data[Value]) / countrows(data)
the answer will be (50 + 80 + 270) / 10 = 40.
However, I want the answer to be (10 + 40 + 90) / 3 = 46.7
I know I have to divide by 3 and can achieve the 3 by
distinctcount(data[ID])
But I find it difficult to extract the 10, 40 and 90.
Can you help me?
There are many ways to achieve that. For example:
Average Value =
VAR Summarized_Table = SUMMARIZE ( Data, Data[ID], Data[Value] )
VAR Total_Value = SUMX ( Summarized_Table, Data[Value] )
VAR Total_Count = COUNTROWS ( Summarized_Table )
RETURN
DIVIDE ( Total_Value, Total_Count )
Result:
Explanation:
First, we create a summarized version of the data, by grouping it on ID and Value columns. Grouping eliminates duplication, so the summary table contains only 3 records. We save the table in a variable;
Second, we sum up values in the summary table (140);
Third, we count number of records in the summary table (3)
Finally, we return the result by dividing sum and count
Alternatively, you can do this:
Average Value =
AVERAGEX ( VALUES ( Data[ID] ), CALCULATE ( AVERAGE ( Data[Value] ) ) )
Result is the same, but the logic is different:
First, using VALUES we create a list of distinct IDs;
Second, we use AVERAGEX to iterate the list, and for each ID calculate its average value. For example, for ID=1, result will be Average of (50)/5= 10;
Finally, we average the averages as (10 + 40 + 90) / 3
My question is about the conditional cumulative sum in SAS. I think it can be explained better by using sample. I have following dataset:
Date Value
01/01/2001 10
02/01/2001 20
03/01/2001 30
04/01/2001 15
05/01/2001 25
06/01/2001 35
07/01/2001 20
08/01/2001 45
09/01/2001 35
I want to find the cumulative sum of value. My condition is if cumulative sum more than 70, it should be 70 and the next cumulative sum should be began from the excessive value over 70 and so on.. More preciesly, my new data should be:
Date Value Cumulative
01/01/2001 10 10
02/01/2001 20 30
03/01/2001 30 60
04/01/2001 15 70
05/01/2001 25 30 ( 75-70=5+25=30)
06/01/2001 35 65
07/01/2001 20 70
08/01/2001 45 60 ( 85-70=15+45=60)
09/01/2001 35 95 ( because its last value)
Many thanks in advance
Here is a solution, although there is bound to be one more elegant. It's split into two parts with if eof to satisfy the last observation condition.
data want;
set test end = eof;
if eof ^= 1 then do;
if cumulative = 70 then cumulative = extra;
Cumulative + value;
extra = cumulative - 70;
if extra > 0 then do;
cumulative = 70;
end;
end;
retain extra;
retain cumulative;
if eof = 1 then cumulative + value;
run;