Forum Discussion

marcospaulo's avatar
marcospaulo
New Member
8 years ago

IF condition for a datetime between two datetimes from another table

Hi,

 

I have two tables, one with a list of quotations and another with the price update of those products.

 

I want to compare the price from the quotations with the price updates, the problem is that for every update, all products have their prices updated (many-to-many).

 

I tried to stablish a period with an initial datetime (the datetime of the update) and a last datetime (the datetime of the next update minus one minute), and with the IF condition, check if the quotation occurred between those datetimes.

 

The problem is, I cant ref those columns into the IF condition on the first table, the Power BI dont even show those columns to choose, I believe it is because I dont have any relationship between those tables (the relationship would be this same conditional).

 

I'm using the datetime format because these proccess occur in small periods of time (a few minutes), been necessary to know both date and time of each information.

 

Could you folks give me a help?

4 Replies

  • marcospaulo yes you are not seeing the columns becuase there is no relationship,you need a product table which can be used to set relationship between those two tables and can work from there.

     

    if you share sample data it will help to provide the solution

    • marcospaulo's avatar
      marcospaulo
      New Member

      The first table (quotation) is like this:

       

      Send DateTimeOperationCompanyProductLocationPeriodVolumePriceStatus
      01/02/201815:00BuyPCONVSE/COjan/182,96-R$ 12,90Lost
      01/02/201815:30BuyDCONVSE/COjan/188,00-R$ 9,00Won
      01/02/201815:30BuyHCONVSE/COjan/182,05-R$ 11,90Lost

       

      And the second (pricing) is like this:

       

      PeriodDateTimeOperationLocationProduct Price 
      jan/1801/02/201814:10:00BuySE/COCONV-R$ 11,90
      jan/1801/02/201814:10:00SellSE/COCONV-R$   9,60
      jan/1801/02/201814:10:00BuyNCONV-R$   8,90
      jan/1801/02/201814:10:00BuyNECONV-R$ 11,90
      jan/1801/02/201814:10:00BuySCONV-R$ 11,90
      jan/1801/02/201814:10:00SellNCONV-R$   6,60
      jan/1801/02/201814:10:00SellNECONV-R$   9,60
      jan/1801/02/201814:10:00SellSCONV-R$   9,60
      jan/1801/02/201815:15:00SellSE/COCONV-R$   9,60
      jan/1801/02/201815:15:00BuyNCONV-R$   8,90
      jan/1801/02/201815:15:00BuyNECONV-R$ 11,90
      jan/1801/02/201815:15:00BuySCONV-R$ 11,90
      jan/1801/02/201815:15:00BuySE/COCONV-R$ 11,90
      jan/1801/02/201815:15:00SellNCONV-R$   6,60
      jan/1801/02/201815:15:00SellNECONV-R$   9,60
      jan/1801/02/201815:15:00SellSCONV-R$   9,60
      • v-xjiin-msft's avatar
        v-xjiin-msft
        Solution Sage

        marcospaulo

         

        In your scenario, what's the logic to compare the price from the quotations with the price updates. For example: let's say the price of the first row in table quotation is -R$ 12,90. Then which one or ones should be compared in table pricing? To compare data between tables, we should get the relation between them first. Even though they are many to many.

         

        Then with many to many relationship in Power BI. Generally, we can combine those columns into one Key column. Then use this key column to make one to one or one to many relationship. Something like:

         

        Key = quotation[Product]&"-"&quotation[Company]&"-"&quotation[Period]

         

        Thanks,
        Xi Jin.