SAP BO - Compare values between rows and conditionally display - sap

I have a request where I need to create an integrity report where I am looking at sales data and verifying that the payment terms are consistent on all items (rows).
Sample data:
Sales # | Line # | Terms Code
100 | 1.0 | N90
100 | 2.0 | N90
101 | 1.0 | N60
101 | 2.0 | P45
101 | 3.0 | N60
Notice that on SO 101, line 2.0 has a different terms code. I need to detect that and only display order 101 on the report.
I was looking at using the PREVIOUS operator in a variable like this:
=If(Previous([Payment Terms Code])=[Payment Terms Code]) Then 0 Else 1
but that looks at the Order 100 line 2.0 and would flag it incorrectly.
I am not sure how I can do this, but maybe using the IN operator some how. Suggestions?

So is appropriate to describe the requirement as you need to see any Sales Orders that have more than one distinct terms code? If so, you can accomplish it like this:
Create a new variable:
Terms Count =Count([Terms Code]) in ([Sales #])
Add this object to the report. You should see "1" for all of the 100 records, and "2" for the 101 records.
Finally, add a filter to the report on Trans Count > 1.

The syntax for the Previous() function is:
Previous(dimension|measure|Self [;Row|col][;(reset_dims)][;offset][;NoNull])
The third parameter, reset_dims allows you to specify when the list of dimensions used to reset the calculation.
Thus, your formula would then be:
Previous([Payment Terms Code]; ([Sales #];[Line #]))
Notes:
You must always place dimensions in parentheses even if there is only one dimension in the list of reset dimensions.
When you specify a set of reset dimensions you must separate them with semi-colon

Related

Search and match indexes in two different columns, return the sum of a third column - Postgresql

I have a table called "tax_info", this table stores the information of the land tax of my city, it goes like this:
taxpayer_code | condominium_num | lot_area | built_area
-------------------------------------------------------------
0010030078-2 | 00-0 | 143 | 130
0010030079-1 | 02-7 | 283 | 57
0010030080-1 | 02-7 | 283 | 48
0010030081-1 | 02-7 | 283 | 50
the taxpayer code first 3 numbers refer to the city district, the next 3 to the block within the district, and the next 4 can refer to the lot in a block if the condo number is 00-0, or to an apartment, or store, etc if the condo number is different than 00-0, in which case all equal condo numbers refer to the same lot within the block.
what I want to do is pass a list of "taxpayer_code" and get the "lot_area" and "built_area" for the lots. the problem is, if the person lives in a condo, her apartment is a fraction of the total built area for the lot. So, if I search for code 0010030078% (the -X number doesn't matter) the result is:
Lot Area = 143 and Built Area = 130
But if I search for 0010030080%, the result I expect is:
Lot Area = 283 and Built Area 155
And if I search for 0010030078%, 0010030079%, the result:
Lot Area = 426 and Built Area 285
So the database should get the taxpayer codes, then look if the condominium number is different from 00-0 for each code passed, if so, it should add to the sum all the other taxpayer codes that share the same condo number within the same district and block. (ideally, if tax codes belonging to different districts or blocks are passed a warning should be returned, and if more tax codes are added to the sum, a listing with all codes added would be nice, but it's okay if that's too much of a hassle!).
I am new to SQL and can't wrap my head around this, I appreciate every help you can give me, thanks!
Hmmm . . . use a subquery and window functions to add up the values that you want:
select ti.*
from (select ti.*,
(case when condominium_num <> '00-0'
then sum(built_area) over (partition by condominium_num)
else built_area
end) as real_built_area
from tax_info ti
) ti
where . . .

Changes to table not designed for SQL

I am supposed to do some changes to an enormous CSV file based on a different file. Therefore I chose to do it in SQL but after further consideration I am not sure how to proceed..
In the 1st table I have a list of contracts. Columns represent some segments the contract belongs to and some products that can be linked to the contract (example in the table below).
Here contract no. 1234 belongs to segments X1 and Y2. There is no product number 1 linked to it, but it has product number 2 linked to it. The product originaly ends on the 1st of January 2030.
cont_n|date|segment_1|segment_2|..|prod_1|date_prod_1|product_2|date_product_2|..
1234 |3011| X1 | Y2 |..| | |YES |01/01/2030 |..
The 2nd file is a list of combinations of segments and an indication how the "date" columns should be adjusted. The example shows following situation - if there is prod_2 linked to the contract which belongs to groups X1 and Y2, end the prod_2 this year. I need this result to alter table no. 1.
prod_no|segment_1|segment_2|result
prod_2 | X1 | Y2 | end the product on anniversary
Ergo I need to get to the result:
cont_n|date|segment_1|segment_2|..|prod_1|date_prod_1|product_2|date_product_2|..
1234 |3011| X1 | Y2 |..| | |YES |30/11/2019 |..
In the original files I have around 600k rows and more than 300 columns (meaning around 100 different products) in table 1 and around 800 possible combinations of segments in table 2.
The algorithm I need to implement (very generally):
for x=1 to 100
IF product_x = YES THEN date_product_x = date + "Seach for result in table2"
Is there a reasonable way how to change the "date_product_x" columns based on the 2nd table or would it be better to find a different solution?
Thanks a lot!
I can only give you a general approach, because the information in your question is general (for example, why does "end the product on anniversary" translate to "30/11/2019"? It's not explained in the question, so I assume you're going to be able to handle that part of the logic).
You can approach this by using an UNPIVOT on Table 1 to get a structure like:
cont_n | segment1 | segment2 | product_number | product_date
You will UNPIVOT..FOR date_product_1 thru date_product_100. You'll either have to type out all 100 column names, or use dynamic sql to build the whole thing.
You'll do some string manipulation to grab the "x" portion of "date_product_x", and turn it into "prod_x", and then you can join to the second table on the two segment columns and the "prod_x" column, get the result column value, and do whatever rules you're doing to get the value you want for date_product_x.
Finally, you take that result, and PIVOT it back to the one-row-per-contract form, and JOIN it to your original table to UPDATE the date_product_x columns.

RDLC grouping rows

I'm trying to do a rdlc table/matrix gruoping by Id.
I have a DataSet which is returning:
Id | name | price | quantity | subtotal | comment
The comment column is optional,also it can have multiple comments per Id so it could return duplicate rows but with different comment column.
Then I want to display in a Table or matrix the data like this
Id | name | quantity | price | subtotal
comment
I mean adding additional rows per comment.
Is it possible to display rows in that format?
If so, What is the best way to achieve it?
This can easily be achieved by using RowGroups. For your example you'd want a stepped report.
Here is an excellent tutorial from MSDN that should be of use to you:
Create a Stepped Report (Report Builder and SSRS)

Spitting long column values to managable size for presenting data neatly

Hi I was wondering if there is a way to split long column values in this case I am using SSRS to get the distinct values with the number of product ID against a category into a matrix/pivot table in SSRS. The problem lies with the amount of distinct category makes it a nightmare to make the report look pretty shall we say. Is there a dynamic way to split the columns in say groups of 10 to make the table look nicer and easy to read. I was thinking of using in operator then the list of values but that means managing the data every time a new category gets added. Is there a dynamic way to present the data in the best way possible? There are 135 distinct category values
Also I am open to suggestions to make the report to nicer if anyone has any thoughts. I am new to SSRS and trying to get to grips with its.
Here is an example of my problem
enter image description here
Are your column names coming back from the database under the SubCat field you note in the comments above? If so I imagine your dataset looks something like this
Subcat | Logno
---------+---------------
SubCatA | 34
SubCatB | 65
SubCatC | 120
SubCatD | 8
SubCatE | 19
You can edit this so that there is an index of each individual category being returned also, using the Row_Number() function. Add the field
ROW_NUMBER() OVER (ORDER BY SubCat ASC) AS ColID
To your query. This will result in the following.
Subcat | LogNo | ColID
-----------+--------------+----------
SubCatA | 34 | 1
SubCatB | 65 | 2
SubCatC | 120 | 3
SubCatD | 8 | 4
SubCatE | 19 | 5
Now there is a numeric identifier for each column you can perform some logic on it to arrange itself nicely on the page.
This solution involves a Tablix, nested inside a Matrix nested inside a Matrix as follows
First create a Matrix (Matrix1), and set it’s datasource to your dataset. Set the Row Group Properties to group on the following expression where ‘4’ is the number of columns you wish to display horizontally.
=CInt(Floor((Fields!ColID.Value - 1) / 4))
Then in the data section of the Matrix (bottom right corner) insert a rectangle and on this insert a new Matrix (Matrix 2). Remove the leftmost row. Set the column header to be the Column Name SubCat. This will automatically set the column grouping to be SubCat.
Finally, in the Data Section of Matrix 2 add a new Rectangle and Add a Tablix on it. Remove the Header Row, and set it to be one column wide only. Set the Data to be the information you wish to display, i.e. LogNo.
Finally, delete the Leftmost and Topmost rows/columns from Matrix 1 to make it look tidier (Note Delete Column Row only! Not associated groups!)
Then when the report is run it should look similar to the following. Note in my example SubCat = ColName, and LogNo = NumItems, and I have multiple values per SubCat.
Hopefully you find this helpful. If not, please ask for clarification.
Can you do something like this:
The following gives the steps (in two columns, down then across)

How do I format numbers in and Access crosstab query to show two decimal places?

I have an Access crosstab query that displays the following results:
| SHORE_TYPE | Total Miles | Class 1 | Class 2 | Class 4 |
| ONSHORE | 31.37 | 0.337121212121212 | 12.4617424242424 | 0 |
I'd like it to display the following results instead. Note the 'Class' columns here show two decimal places:
| SHORE_TYPE | Total Miles | Class 1 | Class 2 | Class 4 |
| ONSHORE | 31.37 | 0.34 | 12.46 | 0.00 |
I've been able to configure the 'Total Miles' column by changing the Format and Decimal Places properties (in the Design View) to "Fixed" and "2," respectively. However, the query column (in Design View) that determines the value in the Class column has only a Format property, which I set to "Fixed"; there is not a Decimal Places property for me to adjust.
I have some similar crosstab queries that are showing the results in the way I desire, but I can't determine any differences between this one and those. Also, I've sometimes seen some of my queries display it the wrong way one time, then the desired way the next time.
This makes me wonder if the problem is a bug in Access, or if there is a something implicitly defined in my code that I should explicitly define.
Here is my SQL:
TRANSFORM IIf(IsNull(Sum([qryPartL].[MILES_OF_PHYS_LENGTH])),0,
Sum([qryPartL].[MILES_OF_PHYS_LENGTH])) AS SumOfMILES_OF_PHYS_LENGTH
SELECT qryPartL.SHORE_TYPE, Sum(qryPartL.MILES_OF_PHYS_LENGTH) AS [Total Miles]
FROM qryPartL
GROUP BY qryPartL.SHORE_TYPE
PIVOT qryPartL.CLASS_LOC_text In ("Class 1","Class 2","Class 4");
EDIT:
After closing and re-opening this query, the Total Miles column is now displaying 31.3714015..., and the properties I had previously set for this column in the Design View are now blank. So, it looks like Access does not consistently save these property settings. At least not in the context in which I was using them.
The trick is to use a series of nested functions.
CDbl: Converts the data to a Double number data type
FormatNumber: Returns an expression formatted as a number with a specified precision (2)
Nz: Returns the specified value (0) when a field is null
The CDbl function won't work if a value is Null.
I also removed the IIf function from the TRANSFORM clause since Nz works better in this case.
Here is the new SQL that returns the desired results. (I've added new lines and indents to make it easier to read. This is a not necessary step, and may in fact not be remembered by Access.)
TRANSFORM
CDbl(
FormatNumber(
Nz(
Sum([qryPartL].[MILES_OF_PHYS_LENGTH])
,0)
,2)
) AS SumOfMILES_OF_PHYS_LENGTH
SELECT qryPartL.SHORE_TYPE,
CDbl(
FormatNumber(
Nz(
Sum(qryPartL.MILES_OF_PHYS_LENGTH)
,0)
,2)
) AS [Total Miles]
FROM qryPartL
GROUP BY qryPartL.SHORE_TYPE
PIVOT qryPartL.CLASS_LOC_text In ("Class 1","Class 2","Class 4");
Thanks to Allen Browne and a tip on his awesome Access website for leading me to this answer.