Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

calculate new table

Hi all,

Hope someone can help me with the following.

 

I have a table A:

ctr_nrdate_inorder_datedate_out
A1-6-20224-6-20225-6-2022
B2-6-202216-6-2022 
C15-6-2022 23-6-2022
D20-6-202225-6-202226-6-2022
E22-6-2022  

 

I want to calculate a new table B, based on table A.

The logic is as follows:

From date_in, the value 1 is mentioned in table B;

When the order date is filled: from that date the value 0 is mentioned in table B instead of value 1;

From the date_out, the value 0 stops in table B;

After that we can calculate the sum for every date column

 

Table B:

ctr_nr1-6-20222-6-20223-6-20224-6-20225-6-20226-6-20227-6-20228-6-20229-6-202210-6-202211-6-202212-6-202213-6-202214-6-202215-6-202216-6-202217-6-202218-6-202219-6-202220-6-202221-6-202222-6-202223-6-202224-6-202225-6-202226-6-2022
A11100                     
B 1111111111111100000000000
C              111111110   
D                   1111100
E                     11111
Total12211111111111211112232211

 

Thanks upfront for your advise!

 

John

  • Hi Anonymous ,

     

    Believe this is possible using a measure however to create a new table you can do the following.

     

    On the query editor follow the steps below:

    • Reference table A
    • Add a custom column with the following code:

     

    try {Number.From([date_in])..Number.From([date_out])} otherwise {Number.From([date_in])..Number.From(  Date.From( DateTime.LocalNow())  )}
    • Expand the new column
    • Format the column has date
    • Add a new column with the following code:
    try if (if [order_date] = null then [Custom] >= [date_in] else [Custom] >= [date_in] and 
    [Custom] < [order_date])
    
     then 1 else
     
     if(if [date_out] = null then [Custom] >= [order_date] else [Custom] >= [order_date] and 
    [Custom] < [date_out])
    
      
      
      then 0 else null
    
    otherwise null

     

    Now you have the new table:

     

     

2 Replies

  • Hi Anonymous ,

     

    Believe this is possible using a measure however to create a new table you can do the following.

     

    On the query editor follow the steps below:

    • Reference table A
    • Add a custom column with the following code:

     

    try {Number.From([date_in])..Number.From([date_out])} otherwise {Number.From([date_in])..Number.From(  Date.From( DateTime.LocalNow())  )}
    • Expand the new column
    • Format the column has date
    • Add a new column with the following code:
    try if (if [order_date] = null then [Custom] >= [date_in] else [Custom] >= [date_in] and 
    [Custom] < [order_date])
    
     then 1 else
     
     if(if [date_out] = null then [Custom] >= [order_date] else [Custom] >= [order_date] and 
    [Custom] < [date_out])
    
      
      
      then 0 else null
    
    otherwise null

     

    Now you have the new table:

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MFelix 

     

    Problem solved, thanks a lot!

     

    John