logo
down
shadow

DAX Query to Calculate % Difference


DAX Query to Calculate % Difference

By : quirkstar
Date : October 18 2020, 03:08 PM
Does that help If you are looking for the difference in average salaries per PayGrade, I think you would want something like the following:
code :
WageGap = IF(DISTINCTCOUNT(Pay[Gender]) > 1,
             CALCULATE(AVERAGE(Pay[Salary]), Pay[Gender] = "M") - 
             CALCULATE(AVERAGE(Pay[Salary]), Pay[Gender] = "F")
             ,0)
Men = IF([WageGap] > 0, [WageGap], BLANK())
Women = IF([WageGap] < 0, -[WageGap], BLANK())


Share : facebook icon twitter icon
SQL Query to Calculate the Rolling Difference by Date

SQL Query to Calculate the Rolling Difference by Date


By : user2752940
Date : March 29 2020, 07:55 AM
this one helps. I cannot seem to work this one out to be exactly what need. , Try this. Use correlated sub-query to find rolling difference
code :
CREATE TABLE #tem
  (SKU      INT,DataDate DATETIME,Web_qty  INT)

INSERT #tem
VALUES( 2,'2014-11-17 00:00:00',404),
       (2,'2014-11-18 00:00:00',373),
       (2,'2014-11-19 00:00:00',1350),
       (66,'2014-11-17 00:00:00',3624),
       (66,'2014-11-18 00:00:00',3576),
       (66,'2014-11-19 00:00:00',3570),
       (67,'2014-11-17 00:00:00',9353),
       (67,'2014-11-18 00:00:00',9297),
       (67,'2014-11-19 00:00:00',9250)

SELECT *,
       Web_qty - (SELECT Web_qty
                  FROM   #tem a
                  WHERE  a.sku = b.SKU
                         AND a.DataDate = Dateadd(dd, -1, b.DataDate)) Roll_diff
FROM   #tem b 
Calculate DateTime difference in query

Calculate DateTime difference in query


By : user3128614
Date : March 29 2020, 07:55 AM
seems to work fine I have a table in which i have START_DATE column which is DATE datatype. I want to get all the SUBSCRIPTION_ID which is older than the last 30 min from the current datetime. Here is my query: , You can amend the where clause with another condition:
code :
start_date < sysdate - 30 / (24 * 60)
Calculate the difference of 2 aggregated Sum in one query

Calculate the difference of 2 aggregated Sum in one query


By : JBogle
Date : March 29 2020, 07:55 AM
will be helpful for those in need This can be done with conditional expressions
code :
from django.db.models import Case, Value, When, IntegerField

gross_total = Loans.object.aggregate(
    gross=Sum(
        Case(
            When(lender=user, then=F('money')),
            default=0, output_field=IntegerField)
        )
    ) - Sum(
        Case(
            When(borrower=user, then=F('money')),
            default=0, output_field=IntegerField)
        )
    )
)
Calculate time difference from this query?

Calculate time difference from this query?


By : Dominik A. Sztorc
Date : March 29 2020, 07:55 AM
help you fix your problem Use cross apply to apply your mindate to your rows, and then take the difference.
Read more about apply here or here
code :
Select A_In.emp_reader_id as empId,A_In.Belongs_to,B.emp_name,A_In.DeviceSerialNumber,
            DT as EntryTime,x.OutTime, Datediff(HOUR,a_in.DT,x.Outtime) as DifferenceTime from trnevents a_in
    CROSS APPLY (select min(DT) as OutTime
             from   trnevents A_Out
             where  EVENTID like '0'
             and    A_Out.emp_reader_id = A_In.emp_reader_id
             and    A_Out.DT > A_In.DT and DATEDIFF(day,A_In.Dt,A_Out.DT)=0
    ) x
How can I calculate the difference between two hashes in a MySQL query?

How can I calculate the difference between two hashes in a MySQL query?


By : Nitin Shingate
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The problem seems to be related to your choice of datatype which is a string type. Using a numeric datatype works in MySQL 5.7 as well as 8.0:
code :
CREATE TABLE `hashes` (
  `id` int(11) NOT NULL,
  `hash` bigint unsigned NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

INSERT INTO `hashes` (`id`, `hash`) VALUES
    (1, 0xb1d0c44a4eb5b5a9),
    (2, 0x1f69f25228ed4a31),
    (3, 0x751a0b19f0c2783f);

SELECT id, HEX(hash), BIT_COUNT(hash ^ 0x751a0b19f0c2783f)
FROM hashes;
id  HEX(hash)           BIT_COUNT(hash ^ 0x751a0b19f0c2783f)
1   B1D0C44A4EB5B5A9    38
2   1F69F25228ED4A31    34
3   751A0B19F0C2783F    0
SELECT id, hash, HEX(hash), HEX(hash ^ 0x751a0b19f0c2783f)
FROM hashes;
id  hash                                                        HEX(hash)           HEX(hash ^ 0x751a0b19f0c2783f)
1   {"type":"Buffer","data":[177,208,196,74,78,181,181,169]}    B1D0C44A4EB5B5A9    751A0B19F0C2783F
2   {"type":"Buffer","data":[31,105,242,82,40,237,74,49]}       1F69F25228ED4A31    751A0B19F0C2783F
3   {"type":"Buffer","data":[117,26,11,25,240,194,120,63]}      751A0B19F0C2783F    751A0B19F0C2783F
id  hash                                                        HEX(hash)           HEX(hash ^ 0x751a0b19f0c2783f)
1   {"type":"Buffer","data":[177,208,196,74,78,181,181,169]}    B1D0C44A4EB5B5A9    C4CACF53BE77CD96
2   {"type":"Buffer","data":[31,105,242,82,40,237,74,49]}       1F69F25228ED4A31    6A73F94BD82F320E
3   {"type":"Buffer","data":[117,26,11,25,240,194,120,63]}      751A0B19F0C2783F    0000000000000000
shadow
Privacy Policy - Terms - Contact Us © soohba.com